The Fix
pip install pydantic==2.6.2
Based on closed pydantic/pydantic issue #8768 · 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%.
@@ -973,7 +973,7 @@ def _apply_alias_generator_to_field_info(
# 1. An alias is not specified
# 2. An alias is specified, but the priority is <= 1
- if alias_generator and (
+ if (
field_info.alias_priority is None
from pydantic import BaseModel, computed_field, ConfigDict, AliasGenerator, AliasChoices
class Box(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
alias_generator=AliasGenerator(
validation_alias=lambda field_name: AliasChoices(
field_name.lower(),
field_name.upper(),
field_name.title(),
field_name.capitalize(),
)
),
)
width: float
height: float
depth: float
extra_field: str | None
@computed_field
def volume(self) -> float:
return self.width * self.height * self.depth
if __name__ == "__main__":
b = Box(WIDTH=1, Height=2, depth=3, Extra_Field="extra")
print(b.model_dump())
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 the alias_generator is expected to return non-string values.\n\n
Why This Fix Works in Production
- Trigger: class Box(BaseModel):
- Mechanism: AliasGenerator does not return a string when used with computed_field decorators, causing schema generation errors
- Why the fix works: Fixes the issue with AliasGenerator causing errors when used with computed_field decorators in Pydantic models. (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.12 in real deployments (not just unit tests).
- AliasGenerator does not return a string when used with computed_field decorators, causing schema generation errors
- Surfaces as: Traceback (most recent call last):
Proof / Evidence
- GitHub issue: #8768
- Fix PR: https://github.com/pydantic/pydantic/pull/8806
- 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.32
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@soggychips, No worries. It'll definitely get released in 2.7, which will be in mid-March. Perhaps we could include this in 2.6.2, which will hopefully be…”
“@soggychips, Thanks for reporting this bug! Seems like this would be a pretty good first issue. Any interest in contributing a fix?”
“@soggychips, Are you testing on main? The following works on the current main branch:”
“Hi, My apologies. I haven't cloned the repository as standalone. I thought this was pushed to the latest version of pydantic on pypi. Any idea…”
Failure Signature (Search String)
- class Box(BaseModel):
Error Message
Stack trace
Error Message
-------------
Traceback (most recent call last):
File "/Users/soggy/Developer/pyt/pydantic_test.py", line 4, in <module>
class Box(BaseModel):
File "/Users/soggy/.pyenv/versions/pyt/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 183, in __new__
complete_model_class(
File "/Users/soggy/.pyenv/versions/pyt/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 517, in complete_model_class
schema = cls.__get_pydantic_core_schema__(cls, handler)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/soggy/.pyenv/versions/pyt/lib/python3.12/site-packages/pydantic/main.py", line 584, in __get_pydantic_core_schema__
return __handler(__source)
^^^^^^^^^^^^^^^^^^^
File "/Users/soggy/.pyenv/versions/pyt/lib/python3.12/site-packages/pydantic/_internal/_schema_generation_shared.py", line 82, in __call__
schema = self._handler(__source_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/soggy/.pyenv/versions/pyt/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 501, in generate_schema
schema = self._generate_schema(obj)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/soggy/.pyenv/versions/pyt/lib/python3.12/site-packages/pydantic/_internal/_generate_schema.py", line 739, in _generate_schema
schema = self._post_process_generated_schema(self._ge
... (truncated) ...
Minimal Reproduction
from pydantic import BaseModel, computed_field, ConfigDict, AliasGenerator, AliasChoices
class Box(BaseModel):
model_config = ConfigDict(
populate_by_name=True,
alias_generator=AliasGenerator(
validation_alias=lambda field_name: AliasChoices(
field_name.lower(),
field_name.upper(),
field_name.title(),
field_name.capitalize(),
)
),
)
width: float
height: float
depth: float
extra_field: str | None
@computed_field
def volume(self) -> float:
return self.width * self.height * self.depth
if __name__ == "__main__":
b = Box(WIDTH=1, Height=2, depth=3, Extra_Field="extra")
print(b.model_dump())
Environment
- Python: 3.12
- Pydantic: 2
What Broke
Schema generation fails, leading to application crashes or incorrect behavior in production.
Why It Broke
AliasGenerator does not return a string when used with computed_field decorators, causing schema generation errors
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/8806
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 the alias_generator is expected to return non-string values.
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.