Yes,
I’ll make a small project in a minute but here is an example with my real data:
for o in models.Observation.objects.exclude(history__isnull=True)[:100]:
print(o)
Yield this error:
raise TypeError(f'Object of type {o.__class__.__name__} '
f'is not JSON serializable')
E TypeError: Object of type datetime is not JSON serializable
Here:
…/…/.venv/lib64/python3.13/site-packages/django_mongodb_backend/operations.py:150: in convert_jsonfield_value
return json.dumps(value)
The history field is defined as:
history = ArrayField(
base_field=models.JSONField(encoder=DjangoJSONEncoder), null=True, blank=True
)
And the data is:
{
"_id": "website_status_code_https_promotions_usa_gov",
"history": [
{
"updated": {
"$date": "2021-12-20T14:04:17.071Z"
},
"value": "200"
},
{
"updated": {
"$date": "2021-12-20T14:04:17.071Z"
},
"value": "403"
},
{
"updated": {
"$date": "2023-03-26T02:37:23.456Z"
},
"value": "200",
"priority": {
"status_code": 0
},
"calculated_priority": 0,
"score": 1
},
{
"updated": {
"$date": "2023-08-04T18:47:40.545Z"
},
"value": "403",
"priority": {
"status_code": 0.32030000000000003
},
"calculated_priority": 0.32030000000000003,
"score": 0.8
}
]
}