The deserialization of DateTime fields doesn't match the documentation
See original GitHub issueAccording to the documentation for marshmallow.fields.DateTime
:
Schema.load returns datetime objects that are timezone-aware.
But that doesn’t seem to be the case in 3.0.0b14:
>>> marshmallow.__version__
'3.0.0b14'
>>> d = marshmallow.fields.DateTime().deserialize('2018-09-18T16:53:11.876810+00:00')
>>> d
datetime.datetime(2018, 9, 18, 16, 53, 11)
>>> repr(d.tzinfo)
'None'
I would have expected the deserialized datetime’s tzinfo
to be set. Or did I misunderstood the documentation?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Deserialize Java 8 LocalDateTime with JacksonMapper
I think your problem is the @DateTimeFormat has no effect at all. As the Jackson is doing the deserialization and it doesn't know...
Read more >Format 'Date' and 'Date Time' fields for import with the Data ...
Date and Date/Time values for the Data Import Wizard must match the format: In the "DATE AND TIME FORMATS" column for the importing...
Read more >Quickstart — marshmallow 3.19.0 documentation
Serialize objects by passing them to your schema's dump method, ... You may not need to output all declared fields every time you...
Read more >DateTime and DateTimeOffset support in System.Text.Json
Attempting to deserialize representations that don't conform to the profile will cause JsonSerializer to throw a JsonException:.
Read more >Issue in getting Opportunity Closedate in angular date input ...
But now when I deserialize using above generated json string, I get this error: Visualforce Remoting Exception: Value does not match ...
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
Ran in to this issue today running unit tests in CircleCI which passed on my local machine. My schemas were loading timezone-aware strings to naive datetime objects, but the docs clearly say “Schema.load returns datetime objects that are timezone-aware.”
Installing python-dateutil fixed the problem. The code explicitly behaves differently depending on whether python-dateutil is installed on the system:
https://github.com/marshmallow-code/marshmallow/blob/fd3f2db051cd1cec6bce9cd18571efd18231a2aa/src/marshmallow/utils.py#L227
Can the docs please be updated to reflect this? That would have saved me some time today!
Or maybe marshmallow can be made dependent on python-dateutil? Would this help with platform independence?
I’m pretty sure that was the reason.
Further refactor will happen in #1234 but I believe the issue about lost timezone info is fixed already thanks to https://github.com/marshmallow-code/marshmallow/pull/1249, reworked in https://github.com/marshmallow-code/marshmallow/pull/1265.
The issue about the docs being inaccurate should be addressed during the refactor in #1234.