8000 📝 Add deprecation info block about `dict()` in `docs/tutorial/body.md` by jomkv · Pull Request #13906 · fastapi/fastapi · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@jomkv
Copy link
Contributor
@jomkv jomkv commented Jul 20, 2025

Description

Updates docs for https://fastapi.tiangolo.com/tutorial/body/#use-the-model with an info about .dict() being deprecated, and that .model_dump() should be used instead.

Refer to discussion #13904 for more details.

Change Preview (refer to the info at the bottom)

image

@github-actions github-actions bot added the docs Documentation about how to use FastAPI label Jul 20, 2025
@github-actions
Copy link
Contributor

@YuriiMotov
Copy link
Member

@jomkv, thanks for you interest!

I remember I saw such note somewhere. I think it would be nice to find it and use the same wording for consistency.
Could you please try to find it?

@jomkv
Copy link
Contributor Author
jomkv commented Jul 20, 2025

@jomkv, thanks for you interest!

I remember I saw such note somewhere. I think it would be nice to find it and use the same wording for consistency. Could you please try to find it?

I actually just copied it from there :) forgot to mention that, sorry. Here is where I found it, just below the code snippet of "Multiple Models".

@YuriiMotov YuriiMotov changed the title 📝 Add deprecated info for dict() in Request Body 📝 Add deprecation info block about dict() in docs/tutorial/body.md Jul 21, 2025
Copy link
Member
@YuriiMotov YuriiMotov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I checked the wording is exactly the same that is used in other places, and this is the only place where .dict() is used without such warning

@github-actions
Copy link
Contributor

@Shihasz
Copy link
Shihasz commented Jul 30, 2025

Pydantic V2 is released long ago and fastapi is no more using V1. I think it is better to change code itself to use model_dump() instead of dict() method which is deprecated already and not recommended to be used in especially in tutorials for new users of the framework. If absolutely necessary, note/info can be added about the method dict() had to be used in v1.

@YuriiMotov
Copy link
Member

Pydantic V2 is released long ago and fastapi is no more using V1. I think it is better to change code itself to use model_dump() instead of dict() method which is deprecated already and not recommended to be used in especially in tutorials for new users of the framework.

FastAPI still supports Pydantic V1 and all code examples from docs are tested with both, Pydantic V1 and V2.
If we change it to .model_dump() then tests with Pydantic V1 will fail.
We could solve this by creating separate code examples for Pydantic V1 and V2 and showing V2 version by default.

Copy link
Member
@tiangolo tiangolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks! 🚀

@tiangolo tiangolo enabled auto-merge (squash) August 31, 2025 10:56
@tiangolo tiangolo merged commit 4584f70 into fastapi:master Aug 31, 2025
51 of 52 checks passed
nilslindemann added a commit to nilslindemann/fastapi that referenced this pull request Sep 1, 2025
commit 176cd8c
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 15:20:12 2025 +0000

    📝 Update release notes

    [skip ci]

commit 1884d76
Author: Sebastián Ramírez <tiangolo@gmail.com>
Date:   Sun Aug 31 17:19:49 2025 +0200

    🔧 Update sponsors: remove Platform.sh (fastapi#14027)

commit 8062aab
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 15:02:29 2025 +0000

    📝 Update release notes

    [skip ci]

commit ee9ccac
Author: Sebastián Ramírez <tiangolo@gmail.com>
Date:   Sun Aug 31 17:02:08 2025 +0200

    🔧 Update sponsors: remove Mobb (fastapi#14026)

commit 5cd4c3b
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 10:59:17 2025 +0000

    📝 Update release notes

    [skip ci]

commit 4584f70
Author: Jom Karlo Verzosa <jomkarlov@gmail.com>
Date:   Sun Aug 31 18:58:56 2025 +0800

    📝 Add deprecation info block about `dict()` in `docs/tutorial/body.md` (fastapi#13906)

    Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>

commit ba9c8fb
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 10:50:12 2025 +0000

    📝 Update release notes

    [skip ci]

commit d9249c1
Author: Valentyn <valentin.druzhinin@gmail.com>
Date:   Sun Aug 31 06:49:48 2025 -0400

    📝 Fix Twitter to be X (Twitter) everywhere in documentation (fastapi#13809)

    Co-authored-by: Valentyn Druzhynin <v.druzhynin@zakaz.global>
    Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>

commit a973e78
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 10:33:32 2025 +0000

    📝 Update release notes

    [skip ci]

commit 1088d2a
Author: Ashish Pandey <126683810+Ashish-Pandey62@users.noreply.github.com>
Date:   Sun Aug 31 16:17:57 2025 +0545

    🐛 Prevent scroll-to-top on restart/fast buttons in `termynal.js` (fastapi#13714)

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

commit 98ec6a6
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 10:29:48 2025 +0000

    📝 Update release notes

    [skip ci]

commit 6b4d292
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 10:29:27 2025 +0000

    📝 Update release notes

    [skip ci]

commit d4ddcc5
Author: z0z0r4 <z0z0r4@outlook.com>
Date:   Sun Aug 31 18:29:21 2025 +0800

    📝 Update testing events documentation (fastapi#13259)

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
    Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>

commit 0e5832a
Author: Hotah Ma <mahongtao0x7e0@163.com>
Date:   Sun Aug 31 18:29:01 2025 +0800

    📝 Remove obsolete `url` field in error responses in docs (fastapi#13655)

    Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>

commit ee2acd8
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 10:03:35 2025 +0000

    📝 Update release notes

    [skip ci]

commit e902ed5
Author: Arnaud Durand <arnaud.durand@live.com>
Date:   Sun Aug 31 12:03:10 2025 +0200

    📝 Bring the `scope` claim in line with the standard in `docs_src/security/tutorial005.py` (fastapi#11189)

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    Co-authored-by: Yurii Motov <yurii.motov.monte@gmail.com>

commit cef1f16
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 09:59:28 2025 +0000

    📝 Update release notes

    [skip ci]

commit 8e63f75
Author: Soul Lee <alus20x@gmail.com>
Date:   Sun Aug 31 18:59:07 2025 +0900

    📝 Update TrustedHostMiddleware Documentation (fastapi#11441)

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    Co-authored-by: Alejandra <90076947+alejsdev@users.noreply.github.com>
    Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
    Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
    Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>

commit e1b9cc0
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 09:56:48 2025 +0000

    📝 Update release notes

    [skip ci]

commit 408b8a9
Author: Denny Biasiolli <dennybiasiolli@users.noreply.github.com>
Date:   Sun Aug 31 11:56:21 2025 +0200

    📝 Remove links to site callbackhell.com that doesn't exist anymore (fastapi#14006)

commit 0817c95
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 09:16:03 2025 +0000

    📝 Update release notes

    [skip ci]

commit c55f713
Author: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
Date:   Sun Aug 31 11:15:41 2025 +0200

    📝 Add permalinks to headers in English docs (fastapi#13993)

    Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>

commit 7653de2
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 09:11:36 2025 +0000

    📝 Update release notes

    [skip ci]

commit 784f068
Author: Sebastián Ramírez <tiangolo@gmail.com>
Date:   Sun Aug 31 11:11:15 2025 +0200

    🛠️ Update `mkdocs_hooks` to handle headers with permalinks when building docs (fastapi#14025)

    Co-authored-by: Yurii Motov <yurii.motov.monte@gmail.com>

commit 6db0577
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Mon Aug 25 20:03:24 2025 +0000

    📝 Update release notes

    [skip ci]

commit 6be02e3
Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date:   Mon Aug 25 22:03:02 2025 +0200

    ⬆ [pre-commit.ci] pre-commit autoupdate (fastapi#14016)

    updates:
    - [github.com/astral-sh/ruff-pre-commit: v0.12.9 → v0.12.10](astral-sh/ruff-pre-commit@v0.12.9...v0.12.10)

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

commit 9cf7b70
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Wed Aug 20 09:11:20 2025 +0000

    📝 Update release notes

    [skip ci]

commit f75c153
Author: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
Date:   Wed Aug 20 11:10:51 2025 +0200

    ⬆ Bump `mkdocs-macros-plugin` from 1.3.7 to 1.3.9 (fastapi#14003)

    Bump mkdocs-macros-plugin from 1.3.7 to 1.3.9

commit 5c3a70d
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Mon Aug 18 21:07:25 2025 +0000

    📝 Update release notes

    [skip ci]

commit 6a45249
Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date:   Mon Aug 18 23:07:04 2025 +0200

    ⬆ [pre-commit.ci] pre-commit autoupdate (fastapi#13999)

    updates:
    - [github.com/astral-sh/ruff-pre-commit: v0.12.8 → v0.12.9](astral-sh/ruff-pre-commit@v0.12.8...v0.12.9)

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

commit c230516
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Mon Aug 18 06:35:06 2025 +0000

    📝 Update release notes

    [skip ci]

commit df77988
Author: Mika <44454249+anfreshman@users.noreply.github.com>
Date:   Mon Aug 18 14:34:40 2025 +0800

    📝 Fix code include for Pydantic models example in `docs/zh/docs/python-types.md` (fastapi#13997)

    Updated the Pydantic expiration example in the Chinese documentation
nilslindemann added a commit to nilslindemann/fastapi that referenced this pull request Sep 1, 2025
commit 3e2dbf9
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 19:34:37 2025 +0000

    📝 Update release notes

    [skip ci]

commit f5b77ff
Author: Sebastián Ramírez <tiangolo@gmail.com>
Date:   Sun Aug 31 21:34:08 2025 +0200

    📝 Add documentation for Behind a Proxy - Proxy Forwarded Headers, using `--forwarded-allow-ips="*"` (fastapi#14028)

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

commit 176cd8c
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 15:20:12 2025 +0000

    📝 Update release notes

    [skip ci]

commit 1884d76
Author: Sebastián Ramírez <tiangolo@gmail.com>
Date:   Sun Aug 31 17:19:49 2025 +0200

    🔧 Update sponsors: remove Platform.sh (fastapi#14027)

commit 8062aab
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 15:02:29 2025 +0000

    📝 Update release notes

    [skip ci]

commit ee9ccac
Author: Sebastián Ramírez <tiangolo@gmail.com>
Date:   Sun Aug 31 17:02:08 2025 +0200

    🔧 Update sponsors: remove Mobb (fastapi#14026)

commit 5cd4c3b
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 10:59:17 2025 +0000

    📝 Update release notes

    [skip ci]

commit 4584f70
Author: Jom Karlo Verzosa <jomkarlov@gmail.com>
Date:   Sun Aug 31 18:58:56 2025 +0800

    📝 Add deprecation info block about `dict()` in `docs/tutorial/body.md` (fastapi#13906)

    Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>

commit ba9c8fb
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 10:50:12 2025 +0000

    📝 Update release notes

    [skip ci]

commit d9249c1
Author: Valentyn <valentin.druzhinin@gmail.com>
Date:   Sun Aug 31 06:49:48 2025 -0400

    📝 Fix Twitter to be X (Twitter) everywhere in documentation (fastapi#13809)

    Co-authored-by: Valentyn Druzhynin <v.druzhynin@zakaz.global>
    Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>

commit a973e78
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 10:33:32 2025 +0000

    📝 Update release notes

    [skip ci]

commit 1088d2a
Author: Ashish Pandey <126683810+Ashish-Pandey62@users.noreply.github.com>
Date:   Sun Aug 31 16:17:57 2025 +0545

    🐛 Prevent scroll-to-top on restart/fast buttons in `termynal.js` (fastapi#13714)

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

commit 98ec6a6
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 10:29:48 2025 +0000

    📝 Update release notes

    [skip ci]

commit 6b4d292
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 10:29:27 2025 +0000

    📝 Update release notes

    [skip ci]

commit d4ddcc5
Author: z0z0r4 <z0z0r4@outlook.com>
Date:   Sun Aug 31 18:29:21 2025 +0800

    📝 Update testing events documentation (fastapi#13259)

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
    Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>

commit 0e5832a
Author: Hotah Ma <mahongtao0x7e0@163.com>
Date:   Sun Aug 31 18:29:01 2025 +0800

    📝 Remove obsolete `url` field in error responses in docs (fastapi#13655)

    Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>

commit ee2acd8
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 10:03:35 2025 +0000

    📝 Update release notes

    [skip ci]

commit e902ed5
Author: Arnaud Durand <arnaud.durand@live.com>
Date:   Sun Aug 31 12:03:10 2025 +0200

    📝 Bring the `scope` claim in line with the standard in `docs_src/security/tutorial005.py` (fastapi#11189)

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    Co-authored-by: Yurii Motov <yurii.motov.monte@gmail.com>

commit cef1f16
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 09:59:28 2025 +0000

    📝 Update release notes

    [skip ci]

commit 8e63f75
Author: Soul Lee <alus20x@gmail.com>
Date:   Sun Aug 31 18:59:07 2025 +0900

    📝 Update TrustedHostMiddleware Documentation (fastapi#11441)

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
    Co-authored-by: Alejandra <90076947+alejsdev@users.noreply.github.com>
    Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
    Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
    Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>

commit e1b9cc0
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 09:56:48 2025 +0000

    📝 Update release notes

    [skip ci]

commit 408b8a9
Author: Denny Biasiolli <dennybiasiolli@users.noreply.github.com>
Date:   Sun Aug 31 11:56:21 2025 +0200

    📝 Remove links to site callbackhell.com that doesn't exist anymore (fastapi#14006)

commit 0817c95
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 09:16:03 2025 +0000

    📝 Update release notes

    [skip ci]

commit c55f713
Author: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
Date:   Sun Aug 31 11:15:41 2025 +0200

    📝 Add permalinks to headers in English docs (fastapi#13993)

    Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>

commit 7653de2
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Sun Aug 31 09:11:36 2025 +0000

    📝 Update release notes

    [skip ci]

commit 784f068
Author: Sebastián Ramírez <tiangolo@gmail.com>
Date:   Sun Aug 31 11:11:15 2025 +0200

    🛠️ Update `mkdocs_hooks` to handle headers with permalinks when building docs (fastapi#14025)

    Co-authored-by: Yurii Motov <yurii.motov.monte@gmail.com>

commit 6db0577
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Mon Aug 25 20:03:24 2025 +0000

    📝 Update release notes

    [skip ci]

commit 6be02e3
Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date:   Mon Aug 25 22:03:02 2025 +0200

    ⬆ [pre-commit.ci] pre-commit autoupdate (fastapi#14016)

    updates:
    - [github.com/astral-sh/ruff-pre-commit: v0.12.9 → v0.12.10](astral-sh/ruff-pre-commit@v0.12.9...v0.12.10)

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

commit 9cf7b70
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Wed Aug 20 09:11:20 2025 +0000

    📝 Update release notes

    [skip ci]

commit f75c153
Author: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com>
Date:   Wed Aug 20 11:10:51 2025 +0200

    ⬆ Bump `mkdocs-macros-plugin` from 1.3.7 to 1.3.9 (fastapi#14003)

    Bump mkdocs-macros-plugin from 1.3.7 to 1.3.9

commit 5c3a70d
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Mon Aug 18 21:07:25 2025 +0000

    📝 Update release notes

    [skip ci]

commit 6a45249
Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date:   Mon Aug 18 23:07:04 2025 +0200

    ⬆ [pre-commit.ci] pre-commit autoupdate (fastapi#13999)

    updates:
    - [github.com/astral-sh/ruff-pre-commit: v0.12.8 → v0.12.9](astral-sh/ruff-pre-commit@v0.12.8...v0.12.9)

    Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

commit c230516
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Mon Aug 18 06:35:06 2025 +0000

    📝 Update release notes

    [skip ci]

commit df77988
Author: Mika <44454249+anfreshman@users.noreply.github.com>
Date:   Mon Aug 18 14:34:40 2025 +0800

    📝 Fix code include for Pydantic models example in `docs/zh/docs/python-types.md` (fastapi#13997)

    Updated the Pydantic expiration example in the Chinese documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation about how to use FastAPI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

0