Skip to content

Commit ba731bb

Browse files
More fixes to non-dicts in schema request/response.
1 parent cb8ff22 commit ba731bb

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
1.1.1 (2017-10-09)
2+
------------------
3+
4+
- Do not attempt to convert empty list to dict for request/response data
5+
16
1.1.0 (2017-10-09)
27
------------------
38

rororo/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111

1212
__author__ = 'Igor Davydenko'
1313
__license__ = 'BSD'
14-
__version__ = '1.1.0'
14+
__version__ = '1.1.1'

rororo/schemas/schema.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def make_error(self,
9393
return error_class(message)
9494

9595
def make_response(self,
96-
data: AnyMapping=None,
97-
**kwargs: Any) -> AnyMapping:
96+
data: Any=None,
97+
**kwargs: Any) -> Any:
9898
r"""Validate response data and wrap it inside response factory.
9999
100100
:param data: Response data. Could be ommited.
@@ -118,7 +118,7 @@ def make_response(self,
118118
return self.response_factory(
119119
*([data] if data is not None else []),
120120
**kwargs)
121-
return data or {}
121+
return data
122122

123123
def validate_request(self,
124124
data: Any,
@@ -174,7 +174,7 @@ def _pure_data(self, data: Any) -> Any:
174174
175175
:param data: Request or response data.
176176
"""
177-
if not isinstance(data, dict):
177+
if not isinstance(data, dict) and not isinstance(data, list):
178178
try:
179179
return dict(data)
180180
except TypeError:

tests/test_schemas.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ def test_schema_array(self):
8686
assert schema.validate_request(TEST_ARRAY) == TEST_ARRAY
8787
assert schema.make_response(TEST_ARRAY) == TEST_ARRAY
8888

89+
def test_schema_array_empty(self):
90+
schema = Schema(schemas.array)
91+
assert schema.validate_request([]) == []
92+
assert schema.make_response([]) == []
93+
8994
def test_schema_default_values(self):
9095
schema = Schema(schemas.default_values)
9196
data = schema.validate_request({})

0 commit comments

Comments
 (0)