You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The documentation does not state that datetime.timedelta is an excluded pydantic type, but when I try to save it to the MongoDB I get the following error:
bson.errors.InvalidDocument: cannot encode object: datetime.timedelta(seconds=21600), of type: <class 'datetime.timedelta'>
The text was updated successfully, but these errors were encountered:
I had to make a custom validator that returns int to make this work. The ODMantic documentation refers to json encoders, but those don't seem to actually be used in the pipeline from a model to the MongoDB Engine. But the custom validator is. Now I just need to figure out if I can create a type based custom validator instead of a member based one without creating a custom type.
The custom validator isn't doing what I thought it was doing. It was replacing the timedelta with an integer in the model class, not just the database. Looking at the motor, I think I need to define a TypeEncoder for it, but I don't see how to add that in ODMantic.
The documentation does not state that datetime.timedelta is an excluded pydantic type, but when I try to save it to the MongoDB I get the following error:
bson.errors.InvalidDocument: cannot encode object: datetime.timedelta(seconds=21600), of type: <class 'datetime.timedelta'>
The text was updated successfully, but these errors were encountered: