Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
3.0: DateTime fields cannot be used as inner field for List or Tuple fields #1357
Between releases 3.0.0rc8 and 3.0.0rc9,
from marshmallow import fields, Schema class MySchema(Schema): times = fields.List(fields.DateTime()) s = MySchema()
It seems like it's treating the parent field as a Schema without checking that it is indeed a schema, so the
I've found the patch below to fix the minimal example above, but I'm not really sure what it's missing out on or how to test it properly:
diff --git a/src/marshmallow/fields.py b/src/marshmallow/fields.py index 0b18e7d..700732e 100644 --- a/src/marshmallow/fields.py +++ b/src/marshmallow/fields.py @@ -1114,7 +1114,7 @@ class DateTime(Field): super()._bind_to_schema(field_name, schema) self.format = ( self.format - or getattr(schema.opts, self.SCHEMA_OPTS_VAR_NAME) + or getattr(getattr(schema, "opts", None), self.SCHEMA_OPTS_VAR_NAME, None) or self.DEFAULT_FORMAT )
When reworking container stuff, I changed
self.inner.parent = self self.inner.name = field_name
AFAIR, I did this merely to avoid duplication. On second thought, I think it was the right thing to do, not only for duplication but to actually bind inner fields to the
Reverting this avoids the error but the inner field's
I think we really mean to call that method, not only in this case but also generally.
or getattr(schema.opts, self.SCHEMA_OPTS_VAR_NAME)
or getattr(self.root.opts, self.SCHEMA_OPTS_VAR_NAME)
The fix in #1357 (comment) removes the error but also the feature:
I didn't double-check that but AFAIU, the change I mentioned above (in container stuff rework) was the right thing to do. The feature was already broken (format set in
Let's do that, then.
Not much time either. The first who gets the time can do it.
For the non-reg tests :
1/ a test that checks the format set in the schema is respected if the
2/ a set of tests asserting the
Perhaps 1/ is useless if 2/ is done.