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
But this is a shame: we end up calling model_dump and model_validate multiple times (which can be expensive with a lot of data), and we loose type hints on the function.
Versions (please complete the following information):
Python version: 3.11
Django version: 5.1
Django-Ninja version: 1.3.0
Pydantic version: 2
The text was updated successfully, but these errors were encountered:
orf
changed the title
[BUG] model_dump defaults to Python output
[BUG] model_dump defaults to mode=pythonAug 21, 2024
Describe the bug
All calls to
BaseModel.model_dump
use the default mode argument, which ispython
and notjson
. For example:django-ninja/ninja/operation.py
Line 271 in b655532
django-ninja/ninja/responses.py
Line 23 in b655532
This means models that use custom types (such as any of these built-in Pydantic types) do not work:
Fails with:
It seems like we should default to using
.model_dump(mode='json')
?You could change
example
to this:But this is a shame: we end up calling
model_dump
andmodel_validate
multiple times (which can be expensive with a lot of data), and we loose type hints on the function.Versions (please complete the following information):
The text was updated successfully, but these errors were encountered: