3.0: DateTime fields cannot be used as inner field for List or Tuple fields
See original GitHub issueBetween releases 3.0.0rc8 and 3.0.0rc9, DateTime
fields have started throwing an error when being instantiated as inner fields of container fields like List
or Tuple
. The snippet below works in <=3.0.0rc8 and throws the error below in >=3.0.0rc9 (and, worryingly, 3.0.0):
from marshmallow import fields, Schema
class MySchema(Schema):
times = fields.List(fields.DateTime())
s = MySchema()
Traceback:
Traceback (most recent call last):
File "test-mm.py", line 8, in <module>
s = MySchema()
File "/Users/victor/.pyenv/versions/marshmallow/lib/python3.6/site-packages/marshmallow/schema.py", line 383, in __init__
self.fields = self._init_fields()
File "/Users/victor/.pyenv/versions/marshmallow/lib/python3.6/site-packages/marshmallow/schema.py", line 913, in _init_fields
self._bind_field(field_name, field_obj)
File "/Users/victor/.pyenv/versions/marshmallow/lib/python3.6/site-packages/marshmallow/schema.py", line 969, in _bind_field
field_obj._bind_to_schema(field_name, self)
File "/Users/victor/.pyenv/versions/marshmallow/lib/python3.6/site-packages/marshmallow/fields.py", line 636, in _bind_to_schema
self.inner._bind_to_schema(field_name, self)
File "/Users/victor/.pyenv/versions/marshmallow/lib/python3.6/site-packages/marshmallow/fields.py", line 1117, in _bind_to_schema
or getattr(schema.opts, self.SCHEMA_OPTS_VAR_NAME)
AttributeError: 'List' object has no attribute 'opts'
It seems like it’s treating the parent field as a Schema without checking that it is indeed a schema, so the schema.opts
statement fails as fields don’t have an opts
attribute.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Fields — marshmallow 3.19.0 documentation
A field that (de)serializes a datetime.timedelta object to an integer or float and vice versa. Tuple (tuple_fields, *args, **kwargs).
Read more >DateTimeField doesn't show in admin system - Stack Overflow
A (sort of) workaround is to add them to the list_display tuple instead. Edit: It will work if you also add your field...
Read more >Model field reference - Django documentation
If a string-based field has null=True , that means it has two possible values for “no data”: NULL , and the empty string....
Read more >Models and Fields — peewee 3.15.4 documentation
import datetime from peewee import * db = SqliteDatabase('my_app.db') class ... The Field class is used to describe the mapping of Model attributes...
Read more >Ecto.Schema — Ecto v3.9.2 - HexDocs
schema/2 is typically used to map data from a persisted source, usually a database ... __schema__(:fields) - Returns a list of all non-virtual...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fix released in 3.0.1
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
DateTime
field is in a container field2/ a set of tests asserting the
_bind_to_schema
method of inner fieldsList
,Dict
,Tuple
is called from container fields (we can useDateTime
with the same test case for that)Perhaps 1/ is useless if 2/ is done.