The statement export keeps the times of all postings in a list. A schema with a List of DateTime fields cannot be created: it raises AttributeError before any data is touched. Tuple and Dict fields that hold a DateTime f…
The statement export keeps the times of all postings in a list. A schema with a List of DateTime fields cannot be created: it raises AttributeError before any data is touched. Tuple and Dict fields that hold a DateTime fail the same way, and so do the same containers holding a Date.
import datetime as dt
from marshmallow import Schema, fields
class StatementSchema(Schema):
history = fields.List(fields.DateTime())
class Meta:
datetimeformat = "%d/%m/%Y %H:%M"
StatementSchema().dump({"history": [dt.datetime(2019, 8, 21, 14, 30)]})
{"history": ["21/08/2019 14:30"]}
AttributeError: 'List' object has no attribute 'opts'
Meta.datetimeformat for DateTime, Meta.dateformat for Date, ISO 8601 when the schema sets neither.Meta, not the outer one's.format given to the inner field itself wins. That case works today.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
datetime-inside-list-crashes-schema
Changes under src/ are evaluated.