Pydantic 2 warns on .dict() because the V1 method names were renamed
Your error
PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0.2 more lines it can showFix it fast
Most common cause, 1 of 2Your own code still uses the Pydantic V1 method names
Swap each old call for its V2 name.
data = user.model_dump(exclude_none=True) # was user.dict(exclude_none=True)
text = user.model_dump_json() # was user.json()
user = User.model_validate(payload) # was User.parse_obj(payload)
user = User.model_validate_json(raw_body) # was User.parse_raw(raw_body)
clone = user.model_copy(update={"name": "x"}) # was user.copy(update=...)Short answer
PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Pydantic 2 renamed the V1 BaseModel methods: .dict() became .model_dump(), .json() became .model_dump_json() and parse_obj() became model_validate(). Rename those calls in your code. When the warning's file path sits inside site-packages, upgrade that library instead. Applies to Pydantic 2.0 to 2.14; V3 is due to drop the old names.
Which cause do you have?
Outside the main script Python hides DeprecationWarning, so switch it on and read the file:line printed in front of PydanticDeprecatedSince20. A file from your project means cause 1. A file under site-packages means cause 2. pytest already lists these in its warnings summary.
python -W default::DeprecationWarning main.pyThen find the line you see in this list and open its fix:
What does the error look like?
PydanticDeprecatedSince20: The `dict` method is deprecated; use `model_dump` instead. Deprecated in Pydantic V2.0 to be removed in V3.0.PydanticDeprecatedSince20: The `json` method is deprecated; use `model_dump_json` instead.PydanticDeprecatedSince20: The `parse_obj` method is deprecated; use `model_validate` instead.
Cause 1 of 2
Your own code still uses the Pydantic V1 method names
You seeThe file:line in the warning is one of your modules, such as app/routes.py:42
Check
PydanticDeprecatedSince20 for dict, json or parse_obj means your code calls a V1 method name on a Pydantic 2 model. Pydantic 2 gave every public BaseModel method a model_ prefix and kept the old names only as deprecated aliases. The migration guide maps each old name to its new one.
grep -rnE "\.(dict|json|parse_obj|parse_raw|copy)\(" --include=*.py app/Fix
Swap each old call for its V2 name. Keyword options such as exclude_none and by_alias are accepted by model_dump as well, and parse_raw maps to model_validate_json. Note the grep also hits plain dict.copy() calls, which need no change.
data = user.model_dump(exclude_none=True) # was user.dict(exclude_none=True)
text = user.model_dump_json() # was user.json()
user = User.model_validate(payload) # was User.parse_obj(payload)
user = User.model_validate_json(raw_body) # was User.parse_raw(raw_body)
clone = user.model_copy(update={"name": "x"}) # was user.copy(update=...)Verify
Run the same command again. No PydanticDeprecatedSince20 line points at a file of yours, and the returned dicts and JSON look the same as before.
python -W default::DeprecationWarning main.pyConfirmed by pydantic.dev
Cause 2 of 2
An installed library calls .dict() on your models
You seeThe file:line in the warning is under site-packages/<some-library>/, and grep finds nothing in your code
Check
Pydantic raises the warning with stacklevel=2, which makes Python name the caller of .dict() rather than Pydantic itself. If that caller lives in site-packages, the library still uses the V1 API, and nothing in your project needs renaming.
pip show <some-library>Fix
Upgrade the library and check its changelog for Pydantic 2 support. If the newest release still warns, silence the warning only for that library's modules, so the same warning from your own code stays visible.
pip install -U <some-library>
# until the library is fixed, in your entry point:
import warnings
from pydantic.warnings import PydanticDeprecatedSince20
warnings.filterwarnings("ignore", category=PydanticDeprecatedSince20, module=r"some_library")Verify
Warnings for that library's path disappear. A test call to .dict() in one of your own modules still prints the warning.
python -W default::DeprecationWarning main.pyConfirmed by docs.python.org
How do I stop it coming back?
- Add error::DeprecationWarning to the filterwarnings list in your pytest config, so a newly added .dict() call fails the test run instead of slipping in.
- Pin pydantic>=2,<3 in your requirements until you have checked the V3 changelog, because V3 is when the old names are due to go.
- Before adding a dependency, check that its release notes mention Pydantic 2 support.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.