Jump to solution
Verify

The Fix

pip install pydantic==2.9.1

Based on closed pydantic/pydantic issue #10333 · PR/commit linked

Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.

Jump to Verify Open PR/Commit
@@ -5,7 +5,7 @@ strategy = [] lock_version = "4.5.0" -content_hash = "sha256:3a584a7e92099980d8871eb23c5549630f86f8e2284884ab3042dd043ddf50f8" +content_hash = "sha256:353e0a512023413e67aad3b741688cdb4c38fe003b8ce6cc28f9f0271d9d7d0a"
repro.py
from pydantic import BaseModel class ExampleModel(BaseModel): example_field: str field_to_be_excluded: str e = ExampleModel(example_field="Hello Pydantic", field_to_be_excluded="To be excluded") e.model_dump(exclude={"field_to_be_excluded": True}) # mypy complains about this
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\npip install pydantic==2.9.1\nWhen NOT to use: Do not use this fix if you rely on the previous behavior of `IncEx` type alias.\n\n

Why This Fix Works in Production

  • Trigger: from pydantic import BaseModel
  • Mechanism: The `IncEx` type alias was incorrectly defined, causing type errors in the `model_dump` method
  • Why the fix works: Fixes the `IncEx` type alias definition, addressing issues with the include/exclude parameters in the model_dump method. (first fixed release: 2.9.1).
Production impact:
  • If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.

Why This Breaks in Prod

  • Shows up under Python 3.12 in real deployments (not just unit tests).
  • The `IncEx` type alias was incorrectly defined, causing type errors in the `model_dump` method
  • Surfaces as: from pydantic import BaseModel

Proof / Evidence

Verified Execution

We executed the runnable minimal repro in a temporary environment and captured exit codes + logs.

  • Status: PASS
  • Ran: 2026-02-11T16:52:29Z
  • Package: pydantic
  • Fixed: 2.9.1
  • Mode: fixed_only
  • Outcome: ok
Logs
affected (exit=None)
fixed (exit=0)

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“@tommasolevato, Thanks for reporting. Indeed, looks like an issue in v2.9.0, we'll work to roll out a fix shortly.”
@sydney-runkle · 2024-09-06 · source
“Yes, ref: https://docs.pydantic.dev/latest/concepts/serialization/#advanced-include-and-exclude”
@tommasolevato · 2024-09-10 · source
“I've found another problem with IncEx, that v2.9.1 did not address: I wasn't sure if it was appropriate to open another issue, so I decided…”
@tommasolevato · 2024-09-10 · source
“Did you mean to write: ? Afaik dict[str, str] isn't supported.”
@Viicos · 2024-09-10 · source

Failure Signature (Search String)

  • from pydantic import BaseModel

Error Message

Stack trace
error.txt
Error Message ------------- from pydantic import BaseModel class ExampleModel(BaseModel): example_field: str field_to_be_excluded: str e = ExampleModel(example_field="Hello Pydantic", field_to_be_excluded="To be excluded") e.model_dump(exclude={"field_to_be_excluded": True}) # mypy complains about this
Stack trace
error.txt
Error Message ------------- class ExampleElement(BaseModel): number: int name: str class ExampleModel(BaseModel): elements: list[ExampleElement] e = ExampleModel(elements=[ExampleElement(number=1, name="Hello Pydantic")]) e.model_dump(exclude={"elements": {"_all": "number"}}) # mypy complains about this

Minimal Reproduction

repro.py
from pydantic import BaseModel class ExampleModel(BaseModel): example_field: str field_to_be_excluded: str e = ExampleModel(example_field="Hello Pydantic", field_to_be_excluded="To be excluded") e.model_dump(exclude={"field_to_be_excluded": True}) # mypy complains about this

Environment

  • Python: 3.12
  • Pydantic: 2

What Broke

Users experienced type errors when using `include` and `exclude` parameters in `model_dump`.

Why It Broke

The `IncEx` type alias was incorrectly defined, causing type errors in the `model_dump` method

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

pip install pydantic==2.9.1

When NOT to use: Do not use this fix if you rely on the previous behavior of `IncEx` type alias.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/pydantic/pydantic/pull/10339

First fixed release: 2.9.1

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not use this fix if you rely on the previous behavior of `IncEx` type alias.

Verify Fix

verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
  • Upgrade behind a canary and run integration tests against the canary before 100% rollout.

Version Compatibility Table

VersionStatus
2.9.1 Broken
2.9.1 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.