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
@@ -120,7 +130,7 @@ In summary, to apply partial updates you would:
120
130
* This way you can update only the values actually set by the user, instead of overriding values already stored with default values in your model.
121
131
* Create a copy of the stored model, updating it's attributes with the received partial updates (using the`update` parameter).
122
132
* Convert the copied model to something that can be stored in your DB (for example, using the`jsonable_encoder`).
123
-
* This is comparable to using the model's`.dict()` method again, but it makes sure (and converts) the values to data types that can be converted to JSON, for example,`datetime` to`str`.
133
+
* This is comparable to using the model's`.model_dump()` method again, but it makes sure (and converts) the values to data types that can be converted to JSON, for example,`datetime` to`str`.
Copy file name to clipboardExpand all lines: docs/en/docs/tutorial/response-model.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -377,6 +377,11 @@ So, if you send a request to that *path operation* for the item with ID `foo`, t
377
377
}
378
378
```
379
379
380
+
!!! info
381
+
In Pydantic v1 the method was called`.dict()`, it was deprecated (but still supported) in Pydantic v2, and renamed to`.model_dump()`.
382
+
383
+
The examples here use `.dict()` for compatibility with Pydantic v1, but you should use `.model_dump()` instead if you can use Pydantic v2.
384
+
380
385
!!! info
381
386
FastAPI uses Pydantic model's`.dict()` with <ahref="https://pydantic-docs.helpmanual.io/usage/exporting_models/#modeldict"class="external-link"target="_blank">its`exclude_unset` parameter</a> to achieve this.