Skip to content

Commit

Permalink
Fix empty body case where schema many=True
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-richert committed Jun 24, 2020
1 parent 893f2ac commit aa1029b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion luckycharms/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def pre_load_func(self, data, many, **kwargs): # pylint: disable=unused-argumen
except DecodeError:
raise BadRequest(message='Invalid protocol buffer data')
else:
data = {}
data = [] if many else {}
return data

# pylint: disable=unexpected-keyword-arg,no-value-for-parameter
Expand Down
16 changes: 16 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,3 +761,19 @@ def business_logic(*args, **kwargs):
'b': 'One',
'c': True
}


def test_many_body(*args, **kwargs):

class TestSchema(BaseModelSchema):

a = fields.Int()
b = fields.String()
c = fields.Boolean()

@TestSchema(many=True)
def business_logic(**kwargs):
return [{"a": 1, "b": "One", "c": True}, {"a": 2, "b": "Two", "c": False}]

with app.test_request_context("/", method="PUT", headers={"Accept": "application/json"}):
business_logic() # Not raising an exception is the test

0 comments on commit aa1029b

Please sign in to comment.