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.

The deserialization of DateTime fields doesn't match the documentation

See original GitHub issue

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

github_iconTop GitHub Comments

4reactions
MattF-NSIDCcommented, Feb 28, 2019

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?

2reactions
lafrechcommented, Jun 24, 2019

deckar01 I know it’s been a while but is it possible your 2.7 environment had python-dateutil installed, but it was not installed in 3.7?

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.

Read more comments on GitHub >

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

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