Initial Checks
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-overridden
however 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
Initial Checks
Description
Overriding
rootonRootModelworks with python3.13 but fails on CPython ~main.with CPython main:
however 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 = 1env 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
Python, Pydantic & OS Version
fails:
works: