Rationale behind fields.DateTime().deserialize('1916') returning datetime(1916, 11, 30, 0, 0)?
See original GitHub issueI just noticed that when I deserialize a date expressed as a ‘YY’ or ‘YY-mm’ string, I get a datetime with month defaulting to 11 and day defaulting to 30 (except for february).
f = fields.DateTime()
f.deserialize('1916')
# datetime.datetime(1916, 11, 30, 0, 0)
f.deserialize('1916-2')
# datetime.datetime(1916, 2, 29, 0, 0)
f.deserialize('1916-3')
# datetime.datetime(1916, 3, 30, 0, 0)
Is this intended?
Shouldn’t this be either rejected or default to a documented value (could be january 1st)?
To prevent this seemingly non-deterministic behavior (it seems reproducible, but I don’t get the rationale), as a workaround, it is possible to set a format explicitly, which rejects such incomplete inputs, but this might not always be desired (be loose on inputs / strict on outputs).
f = fields.DateTime(format='%Y-%m-%d')
f.deserialize('1916-05-04')
# datetime.datetime(1916, 5, 4, 0, 0)
f.deserialize('1916')
# marshmallow.exceptions.ValidationError: Not a valid datetime.
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (9 by maintainers)
Top Results From Across the Web
Symfony Serializer of DateTime Response String
When storing the due date, the timezone is saved and there is an additional timezone field stored. Is there a way to pull...
Read more >Fields — marshmallow 3.19.0 documentation
A field that takes the value returned by a Schema method. A formatted naive datetime string. Allows you to nest a Schema inside...
Read more >eventsource.cs
Project path: ndp\clr\src\bcl\mscorlib.csproj. Files: 1,258. Lines of code: 484,913. Bytes: 20,489,855. Declared symbols: 38,440. Declared types: 3,122
Read more >Module Code - Deform Demo
OneOf([x[0] for x in choices]), widget=deform.widget. ... Range( min=datetime.datetime( datetime.date.today().year, 1, 1, 12, 30, tzinfo=iso8601.
Read more >Release Notes — Airflow Documentation
New to this release of Airflow is the concept of Datasets to Airflow, and with it a new way of scheduling dags: data-aware...
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 FreeTop 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
Top GitHub Comments
Exactly
@lnielsen See the discussion on https://github.com/marshmallow-code/marshmallow/pull/605 :