Jump to solution
Verify

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%.

Jump to Verify Open PR/Commit
@@ -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,
repro.py
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)
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.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).
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.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

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
affected (exit=None)
fixed (exit=0)

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!!”
@sydney-runkle · 2024-03-08 · confirmation · source
“> Should be fixed now in 2.6.4 :) Can confirm; thanks so much!”
@dfarley1 · 2024-03-12 · confirmation · source
“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”
@dmontagu · 2024-03-07 · confirmation · source
“@dfarley1, Thanks for reporting this. That does seem quite odd. Let's get @dmontagu on the case.”
@sydney-runkle · 2024-03-07 · source

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
signature.txt
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.txt
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

repro.py
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

When NOT to use: Do not use this fix if your model requires strict optional behavior.

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.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not use this fix if your model requires strict optional behavior.

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.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.