The Fix
pip install pydantic==2.6.2
Based on closed pydantic/pydantic issue #8954 · 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%.
@@ -340,16 +340,25 @@ def __init__(
self.info = info
- def to_argument(self, current_info: TypeInfo, typed: bool, force_optional: bool, use_alias: bool) -> Argument:
+ def to_argument(
+ self,
from pydantic import BaseModel as _BaseModel
from pydantic import ConfigDict
from typing import Optional
class BaseModel(_BaseModel):
model_config = ConfigDict(extra="forbid")
class Broken1(BaseModel):
thing: str | None
class Broken2(BaseModel):
thing: Optional[int]
class Works1(BaseModel):
thing: str
class Works2(BaseModel):
thing: str | int | None
broken1 = Broken1(thing="") # <--- Unexpected keyword argument "thing" for "Broken" Mypy (call-arg)
broken2 = Broken2(thing=5) # <--- Unexpected keyword argument "thing" for "Broken" Mypy (call-arg)
works1 = Works1(thing="")
works2 = Works2(thing=7)
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\npip install pydantic==2.6.2\nWhen NOT to use: Do not use this fix if your model requires strict optional behavior.\n\n
Why This Fix Works in Production
- Trigger: "Unexpected keyword argument" when using `ConfigDict(extra="forbid")`
- Mechanism: The mypy type checker raised unexpected keyword argument errors due to a bug with no_strict_optional=True
- Why the fix works: Fixes a bug with no_strict_optional=True that caused mypy to raise unexpected keyword argument errors when using ConfigDict(extra='forbid'). (first fixed release: 2.6.2).
- 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.10.12 in real deployments (not just unit tests).
- The mypy type checker raised unexpected keyword argument errors due to a bug with no_strict_optional=True
- Production symptom (often without a traceback): "Unexpected keyword argument" when using `ConfigDict(extra="forbid")`
Proof / Evidence
- GitHub issue: #8954
- Fix PR: https://github.com/pydantic/pydantic/pull/8826
- First fixed release: 2.6.2
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.53
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.6.2
- Mode: fixed_only
- Outcome: ok
Logs
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“I'll pull that fix into the 2.6.4 release, hopefully today! Marking as resolved :). Thanks @dmontagu!!”
“> Should be fixed now in 2.6.4 :) Can confirm; thanks so much!”
“I am able to reproduce this in v2.6.3, but not on main, so I think it should be fixed in the next pydantic release”
“@dfarley1, Thanks for reporting this. That does seem quite odd. Let's get @dmontagu on the case.”
Failure Signature (Search String)
- "Unexpected keyword argument" when using `ConfigDict(extra="forbid")`
- When using `ConfigDict(extra="forbid")`, mypy complains about "Unexpected keyword argument" for all fields on a model, but only if one of the fields is `Optional[]` with a single
Copy-friendly signature
Failure Signature
-----------------
"Unexpected keyword argument" when using `ConfigDict(extra="forbid")`
When using `ConfigDict(extra="forbid")`, mypy complains about "Unexpected keyword argument" for all fields on a model, but only if one of the fields is `Optional[]` with a single type.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
"Unexpected keyword argument" when using `ConfigDict(extra="forbid")`
When using `ConfigDict(extra="forbid")`, mypy complains about "Unexpected keyword argument" for all fields on a model, but only if one of the fields is `Optional[]` with a single type.
Minimal Reproduction
from pydantic import BaseModel as _BaseModel
from pydantic import ConfigDict
from typing import Optional
class BaseModel(_BaseModel):
model_config = ConfigDict(extra="forbid")
class Broken1(BaseModel):
thing: str | None
class Broken2(BaseModel):
thing: Optional[int]
class Works1(BaseModel):
thing: str
class Works2(BaseModel):
thing: str | int | None
broken1 = Broken1(thing="") # <--- Unexpected keyword argument "thing" for "Broken" Mypy (call-arg)
broken2 = Broken2(thing=5) # <--- Unexpected keyword argument "thing" for "Broken" Mypy (call-arg)
works1 = Works1(thing="")
works2 = Works2(thing=7)
Environment
- Python: 3.10.12
- Pydantic: 2
What Broke
Mypy raises unexpected keyword argument errors for models using ConfigDict(extra='forbid').
Why It Broke
The mypy type checker raised unexpected keyword argument errors due to a bug with no_strict_optional=True
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install pydantic==2.6.2
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/8826
First fixed release: 2.6.2
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- Do not use this fix if your model requires strict optional behavior.
Verify Fix
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
| Version | Status |
|---|---|
| 2.6.2 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.