question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

3.0: DateTime fields cannot be used as inner field for List or Tuple fields

See original GitHub issue

Between 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:closed
  • Created 4 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
sloriacommented, Aug 21, 2019

Fix released in 3.0.1

0reactions
lafrechcommented, Aug 21, 2019

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 field

2/ a set of tests asserting the _bind_to_schema method of inner fields List, Dict, Tuple is called from container fields (we can use DateTime with the same test case for that)

Perhaps 1/ is useless if 2/ is done.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found