Repository navigation
Possible regression against CPython main (future 3.14) #11097
Copy link
Copy link
Closed
Labels
Description
Initial Checks
- I confirm that I'm using Pydantic V2
Description
Overriding root on RootModel works with python3.13 but fails on CPython ~main.
with CPython main:
>>> import pydantic
... class Fails(pydantic.RootModel):
... root: list[str] = pydantic.Field(alias='aardvark')
...
Traceback (most recent call last):
File "<python-input-4>", line 2, in <module>
class Fails(pydantic.RootModel):
root: list[str] = pydantic.Field(alias='aardvark')
File "/home/tcaswell/.virtualenvs/cp314-clang/lib/python3.14/site-packages/pydantic/_internal/_model_construction.py", line 113, in __new__
private_attributes = inspect_namespace(
namespace, config_wrapper.ignored_types, class_vars, base_field_names
)
File "/home/tcaswell/.virtualenvs/cp314-clang/lib/python3.14/site-packages/pydantic/_internal/_model_construction.py", line 496, in inspect_namespace
raise PydanticUserError(
...<3 lines>...
)
pydantic.errors.PydanticUserError: Field 'root' defined on a base class was overridden by a non-annotated attribute. All field definitions, including overrides, require a type annotation.
For further information visit https://errors.pydantic.dev/2.10/u/model-field-overriddenhowever the code works with 3.13.
I have bisected this to python/cpython#119361 / python/cpython@9b8611e . I am not sure if this is something pydandtic needs to adapt to, something pyO3 needs to adapt to (I use the undocumented $UNSAFE_PYO3_SKIP_VERSION_CHECK = 1 env to get it to build so a bit in 🐉 land), or a regression in CPython that needs to be addressed. Reporting here first because I suspect that this is something pydantic needs to adapt to and un-lazy the annotations on the sub-classes before validating, but I am at the edges of my understanding.
Example Code
import pydantic
class Fails(pydantic.RootModel):
root: list[str] = pydantic.Field(alias='aardvark')Python, Pydantic & OS Version
fails:
pydantic version: 2.10.3
pydantic-core version: 2.27.1
pydantic-core build: profile=release pgo=false
install path: /home/tcaswell/.virtualenvs/cp314-clang/lib/python3.14/site-packages/pydantic
python version: 3.14.0a2+ (heads/main:79b7cab50a3, Dec 7 2024, 16:24:57) [Clang 18.1.8 ]
platform: Linux-6.12.4-arch1-1-x86_64-with-glibc2.40
related packages: typing_extensions-4.12.2 mypy-1.13.0 pydantic-settings-2.6.1 fastapi-0.115.6
commit: unknown
works:
pydantic version: 2.10.3
pydantic-core version: 2.27.1
pydantic-core build: profile=release pgo=false
install path: /home/tcaswell/.virtualenvs/cp313-clang/lib/python3.13/site-packages/pydantic
python version: 3.13.1+ (heads/3.13:310efdabf55, Dec 9 2024, 20:15:13) [Clang 18.1.8 ]
platform: Linux-6.12.4-arch1-1-x86_64-with-glibc2.40
related packages: typing_extensions-4.12.2 mypy-1.13.0 pydantic-settings-2.6.1 fastapi-0.115.6
commit: unknown
Reactions are currently unavailable
Activity
Viicos commentedon Dec 12, 2024
Thanks, but we don't support 3.14 yet and we are aware of the PEP 649 changes (which will require substantial amount of work). We're planning on tackling this in some months.
mpkocher commentedon Dec 13, 2024
@Viicos Is there a specific issue filed to handle and define these 3.14 issue(s)?
Viicos commentedon Dec 14, 2024
I'll wait for PEP 649 to be fully implemented first, and then I'll open an issue after taking a quick look at how things can be implemented on our end.
tacaswell commentedon May 2, 2025
pydantic-core is now failing to build on py3.14 with the following:
which I expect is due to the same root cause (PEP 649 and annotations being lazy).