The Fix
Fixes a bug where unsupported types could not be used with PlainValidator in Pydantic 2.6.0, restoring functionality from version 2.5.3.
Based on closed pydantic/pydantic issue #8697 · 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%.
@@ -153,8 +153,19 @@ class Model(BaseModel):
def __get_pydantic_core_schema__(self, source_type: Any, handler: _GetCoreSchemaHandler) -> core_schema.CoreSchema:
- schema = handler(source_type)
- serialization = core_schema.wrap_serializer_function_ser_schema(function=lambda v, h: h(v), schema=schema)
+ # Note that for some valid uses of PlainValidator, it is not possible to generate a core schema for the
from typing import TypeAlias, Annotated
import pydantic
from pydantic import PlainValidator
print(pydantic.version.version_info())
class UnsupportedClass:
pass
PreviouslySupportedType: TypeAlias = Annotated[
UnsupportedClass,
PlainValidator(lambda _: UnsupportedClass())
]
# The next line fails on 2.6.0 and main (29906d744d8bae7a7e5fcba653d3867454a9e1d5)
type_adapter = pydantic.TypeAdapter(PreviouslySupportedType)
print(type_adapter.validate_python("abcdefg"))
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Apply the official fix\nFixes a bug where unsupported types could not be used with PlainValidator in Pydantic 2.6.0, restoring functionality from version 2.5.3.\nWhen NOT to use: This fix should not be used if the application relies on the previous behavior of throwing errors for unsupported types.\n\n
Why This Fix Works in Production
- Trigger: pydantic version: 2.6.0
- Mechanism: The change in behavior was caused by an earlier commit that altered how handlers are called
- 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.11 in real deployments (not just unit tests).
- The change in behavior was caused by an earlier commit that altered how handlers are called
- Surfaces as: pydantic version: 2.6.0
Proof / Evidence
- GitHub issue: #8697
- Fix PR: https://github.com/pydantic/pydantic/pull/8710
- Reproduced locally: No (not executed)
- Last verified: 2026-02-11
- Confidence: 0.70
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.26
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“@MHajoha, Thanks for bringing this to our attention. This change wasn't intentional - that pattern is indeed something that we want to support! We'll look…”
Failure Signature (Search String)
- pydantic version: 2.6.0
Error Message
Stack trace
Error Message
-------------
pydantic version: 2.6.0
pydantic-core version: 2.16.1
pydantic-core build: profile=release pgo=true
install path: /home/maxh/Work/project/.venv311/lib/python3.11/site-packages/pydantic
python version: 3.11.1 (main, Jan 12 2023, 14:43:37) [GCC 12.2.0]
platform: Linux-6.7.2-zen1-1-zen-x86_64-with-glibc2.38
related packages: typing_extensions-4.9.0
commit: unknown
Traceback (most recent call last):
File "/home/maxh/Work/project/.venv311/lib/python3.11/site-packages/pydantic/type_adapter.py", line 207, in __init__
core_schema = _getattr_no_parents(type, '__pydantic_core_schema__')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/maxh/Work/project/.venv311/lib/python3.11/site-packages/pydantic/type_adapter.py", line 98, in _getattr_no_parents
raise AttributeError(attribute)
AttributeError: __pydantic_core_schema__
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/maxh/Work/project/pydantic_261_example.py", line 19, in <module>
type_adapter = pydantic.TypeAdapter(PreviouslySupportedType)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/maxh/Work/project/.venv311/lib/python3.11/site-packages/pydantic/type_adapter.py", line 209, in _
... (truncated) ...
Stack trace
Error Message
-------------
(.venv311-devpydantic) [maxh@laptop ~/Work/project]$ python pydantic_261_example.py
pydantic version: 2.6.0
pydantic-core version: 2.16.1
pydantic-core build: profile=release pgo=true
install path: /home/maxh/Work/project/.venv311-devpydantic/lib/python3.11/site-packages/pydantic
python version: 3.11.1 (main, Jan 12 2023, 14:43:37) [GCC 12.2.0]
platform: Linux-6.7.2-zen1-1-zen-x86_64-with-glibc2.38
related packages: typing_extensions-4.9.0
commit: unknown
Traceback (most recent call last):
File "/home/maxh/Work/project/.venv311-devpydantic/lib/python3.11/site-packages/pydantic/type_adapter.py", line 207, in __init__
core_schema = _getattr_no_parents(type, '__pydantic_core_schema__')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/maxh/Work/project/.venv311-devpydantic/lib/python3.11/site-packages/pydantic/type_adapter.py", line 98, in _getattr_no_parents
raise AttributeError(attribute)
AttributeError: __pydantic_core_schema__
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/maxh/Work/project/pydantic_261_example.py", line 19, in <module>
type_adapter = pydantic.TypeAdapter(PreviouslySupportedType)
^^^^^^^^^^^^^^^^^^^^^^^
... (truncated) ...
Minimal Reproduction
from typing import TypeAlias, Annotated
import pydantic
from pydantic import PlainValidator
print(pydantic.version.version_info())
class UnsupportedClass:
pass
PreviouslySupportedType: TypeAlias = Annotated[
UnsupportedClass,
PlainValidator(lambda _: UnsupportedClass())
]
# The next line fails on 2.6.0 and main (29906d744d8bae7a7e5fcba653d3867454a9e1d5)
type_adapter = pydantic.TypeAdapter(PreviouslySupportedType)
print(type_adapter.validate_python("abcdefg"))
Environment
- Python: 3.11
- Pydantic: 2
What Broke
Users experienced errors when using unsupported types with PlainValidator, leading to application crashes.
Why It Broke
The change in behavior was caused by an earlier commit that altered how handlers are called
Fix Options (Details)
Option A — Apply the official fix
Fixes a bug where unsupported types could not be used with PlainValidator in Pydantic 2.6.0, restoring functionality from version 2.5.3.
Fix reference: https://github.com/pydantic/pydantic/pull/8710
Last verified: 2026-02-11. Validate in your environment.
When NOT to Use This Fix
- This fix should not be used if the application relies on the previous behavior of throwing errors for unsupported types.
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.
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.