Loading Datetime Objects
See original GitHub issueMaybe this is not so much of an issue but a misunderstanding on my side, so I’d think the following pytest-style unit test should not raise a validation error, since a datetime.datetime
instance should satisfy the property of being a a datetime already:
from marshmallow import Schema, fields
import datetime
class SomeSchema(Schema):
element = fields.DateTime()
def test_datetime_loading_accepts_datetime_object():
schema = SomeSchema(strict=True)
res = schema.load({"element": datetime.datetime.now()})
I do however get a validation error marshmallow.exceptions.ValidationError: {'element': ['Not a valid datetime.']}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:8
- Comments:10 (1 by maintainers)
Top Results From Across the Web
How to convert to a Python datetime object with JSON.loads?
If the schema is known, it should be pretty easy to make a function, which parses json and substitutes string representations with datetime....
Read more >Using Python datetime to Work With Dates and Times
In this tutorial, you'll focus on using the Python datetime module. The main focus of datetime is to make it less complicated to...
Read more >Python datetime (With Examples) - Programiz
One of the classes defined in the datetime module is datetime class. We then used now() method to create a datetime object containing...
Read more >Ultimate Guide to Datetime! Python date and time objects for ...
Hi everyone! today we will talk about the Datetime module, which helps us load and manipulate date and time data in Python.
Read more >datetime — Basic date and time types — Python 3.11.1 ...
A timedelta object represents a duration, the difference between two dates or times. class datetime.timedelta(days= ...
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
I’m temporarily using this so deserialization accepts datetimes instances:
If are serializing(dump) a DateTime field then you need to provide a datetime object:
If you are going the other way deserializing(load) then you can use a string: