The basket summary has a has_items flag that is dumped straight from the list of items: an empty basket should give false, anything else true. Dumping fails as soon as the value is a list or a dict.
The basket summary has a has_items flag that is dumped straight from the list of items: an empty basket should give false, anything else true. Dumping fails as soon as the value is a list or a dict.
from marshmallow import Schema, fields
class BasketSchema(Schema):
has_items = fields.Boolean()
BasketSchema().dump({"has_items": []})
BasketSchema().dump({"has_items": [1, 2]})
{"has_items": False}
{"has_items": True}
TypeError: unhashable type: 'list'
bool(value). That is what happens today for values such as "maybe" or 2, and it should happen for lists and dicts as well."off" dumps as False, "yes" as True, also with custom sets.Adapted from marshmallow-code/marshmallow (MIT).
Visible test command
pytest testsThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
boolean-field-crashes-on-lists
Changes under src/ are evaluated.