Jump to solution
Verify

The Fix

pip install pydantic==1.10.18

Based on closed pydantic/pydantic issue #10105 · 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
@@ -18,7 +18,7 @@ from ._import_utils import import_cached_base_model, import_cached_field_info from ._repr import Representation -from ._typing_extra import get_cls_type_hints_lenient, get_type_hints, is_classvar, is_finalvar +from ._typing_extra import get_cls_type_hints_lenient, is_classvar, is_finalvar
repro.py
from openai.types.chat import ChatCompletionAssistantMessageParam from pydantic import BaseModel class FunctionCall: ... class Test(BaseModel): test: ChatCompletionAssistantMessageParam # PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class '__main__.FunctionCall'>. # Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.
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==1.10.18\nWhen NOT to use: This fix should not be applied if your code relies on the previous behavior of name resolution.\n\n

Why This Fix Works in Production

  • Trigger: % rye run python
  • Mechanism: Namespace conflicts occur when class names are reused in Pydantic model generation
  • Why the fix works: Addresses the issue of namespace conflicts in Pydantic model generation by removing an old typing function that caused errors when class names were reused. (first fixed release: 1.10.18).
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 in real deployments (not just unit tests).
  • Namespace conflicts occur when class names are reused in Pydantic model generation
  • Surfaces as: % rye run python

Proof / Evidence

Discussion

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

“Turns out this was fixed by https://github.com/pydantic/pydantic/pull/10063. It will be included in the next 2.9 release.”
@Viicos · 2024-08-14 · source
“I've tried reproducing the issue in multiple ways without any success. Could you please provide the output of the following code:”
@Viicos · 2024-08-12 · source
“I created a new virtualenv, installed the latest openai and pydantic, and can reproduce. The output is Package versions Pydantic version details <details> <summary>Full output</summary>…”
@jackmpcollins · 2024-08-14 · source

Failure Signature (Search String)

  • % rye run python

Error Message

Stack trace
error.txt
Error Message ------------- % rye run python Python 3.12.4 (main, Jul 25 2024, 22:11:22) [Clang 18.1.8 ] on darwin Type "help", "copyright", "credits" or "license" for more information. >> from openai.types.chat import ChatCompletionAssistantMessageParam >> >> print(ChatCompletionAssistantMessageParam.__annotations__['function_call']) ForwardRef('Optional[FunctionCall]', module='openai.types.chat.chat_completion_assistant_message_param') >> print(ChatCompletionAssistantMessageParam.__annotations__['function_call'].__forward_module__) openai.types.chat.chat_completion_assistant_message_param >> >> from pydantic import BaseModel >> >> >> class FunctionCall: ... ... ... >> import sys >> >> print(sys.modules['openai.types.chat.chat_completion_assistant_message_param'].__dict__['FunctionCall']) <class 'openai.types.chat.chat_completion_assistant_message_param.FunctionCall'> >> >> >> class Test(BaseModel): ... test: ChatCompletionAssistantMessageParam ... Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/jack/Code/test-pydantic-bug/.venv/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 205, in __new__ complete_model_class( File "/Users/jack/Code/test-pydantic-bug/.venv/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py", line 534, in complete_model_class schema = cls.__get_pydantic_core_schema__(cls, handler ... (truncated) ...

Minimal Reproduction

repro.py
from openai.types.chat import ChatCompletionAssistantMessageParam from pydantic import BaseModel class FunctionCall: ... class Test(BaseModel): test: ChatCompletionAssistantMessageParam # PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class '__main__.FunctionCall'>. # Set `arbitrary_types_allowed=True` in the model_config to ignore this error or implement `__get_pydantic_core_schema__` on your type to fully support it.

Environment

  • Python: 3.10
  • Pydantic: 2

What Broke

Pydantic raises PydanticSchemaGenerationError when reusing class names, causing schema generation failures.

Why It Broke

Namespace conflicts occur when class names are reused in Pydantic model generation

Fix Options (Details)

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

pip install pydantic==1.10.18

When NOT to use: This fix should not be applied if your code relies on the previous behavior of name resolution.

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/10063

First fixed release: 1.10.18

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

  • This fix should not be applied if your code relies on the previous behavior of name resolution.

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
1.10.18 Fixed

Related Issues

No related fixes found.

Sources

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