Skip to content

Possible regression against CPython main (future 3.14) #11097

Closed

Description

@tacaswell

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

Activity

  1. Viicos commented on Dec 12, 2024

    @Viicos
    Member

    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.

  2. mpkocher commented on Dec 13, 2024

    @mpkocher

    @Viicos Is there a specific issue filed to handle and define these 3.14 issue(s)?

  3. Viicos commented on Dec 14, 2024

    @Viicos
    Member

    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.

  4. tacaswell commented on May 2, 2025

    @tacaswell
    Author

    pydantic-core is now failing to build on py3.14 with the following:

          error: failed to run custom build command for `pydantic-core v2.33.2 (/tmp/pip-install-9ncbhy4u/pydantic-core_53401a52cce74fab9860bde9c1518d21)`
    
          Caused by:
            process didn't exit successfully: `/tmp/pip-install-9ncbhy4u/pydantic-core_53401a52cce74fab9860bde9c1518d21/target/release/build/pydantic-core-27ad7284376df324/build-script-build` (exit status: 101)
            --- stdout
            cargo:rustc-check-cfg=cfg(Py_LIMITED_API)
            cargo:rustc-check-cfg=cfg(Py_GIL_DISABLED)
            cargo:rustc-check-cfg=cfg(PyPy)
            cargo:rustc-check-cfg=cfg(GraalPy)
            cargo:rustc-check-cfg=cfg(py_sys_config, values("Py_DEBUG", "Py_REF_DEBUG", "Py_TRACE_REFS", "COUNT_ALLOCS"))
            cargo:rustc-check-cfg=cfg(pyo3_disable_reference_pool)
            cargo:rustc-check-cfg=cfg(pyo3_leak_on_drop_without_reference_pool)
            cargo:rustc-check-cfg=cfg(Py_3_7)
            cargo:rustc-check-cfg=cfg(Py_3_8)
            cargo:rustc-check-cfg=cfg(Py_3_9)
            cargo:rustc-check-cfg=cfg(Py_3_10)
            cargo:rustc-check-cfg=cfg(Py_3_11)
            cargo:rustc-check-cfg=cfg(Py_3_12)
            cargo:rustc-check-cfg=cfg(Py_3_13)
            cargo:rustc-check-cfg=cfg(Py_3_14)
            cargo:rustc-cfg=Py_3_7
            cargo:rustc-cfg=Py_3_8
            cargo:rustc-cfg=Py_3_9
            cargo:rustc-cfg=Py_3_10
            cargo:rustc-cfg=Py_3_11
            cargo:rustc-cfg=Py_3_12
            cargo:rustc-cfg=Py_3_13
            cargo:rustc-cfg=Py_3_14
            cargo:rustc-check-cfg=cfg(has_coverage_attribute)
            cargo:rustc-check-cfg=cfg(specified_profile_use)
            cargo:rerun-if-changed=python/pydantic_core/core_schema.py
            cargo:rerun-if-changed=generate_self_schema.py
    
            --- stderr
            Traceback (most recent call last):
              File "/tmp/pip-install-9ncbhy4u/pydantic-core_53401a52cce74fab9860bde9c1518d21/generate_self_schema.py", line 245, in <module>
                main()
                ~~~~^^
              File "/tmp/pip-install-9ncbhy4u/pydantic-core_53401a52cce74fab9860bde9c1518d21/generate_self_schema.py", line 212, in main
                m = re.search(r"Literal\['(.+?)']", type_.__forward_arg__)
                                                    ^^^^^^^^^^^^^^^^^^^^^
            AttributeError: 'str' object has no attribute '__forward_arg__'
    
            thread 'main' panicked at build.rs:29:9:
            generate_self_schema.py failed with exit status: 1
            note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
          warning: build failed, waiting for other jobs to finish...
          💥 maturin failed
            Caused by: Failed to build a native library through cargo
            Caused by: Cargo build finished with "exit status: 101": `env -u CARGO PYO3_ENVIRONMENT_SIGNATURE="cpython-3.14-64bit" PYO3_PYTHON="/home/tcaswell/.virtualenvs/cp314-clang/bin/python3" PYTHON_SYS_EXECUTABLE="/home/tcaswell/.virtualenvs/cp314-clang/bin/python3" "cargo" "rustc" "--features" "pyo3/extension-module" "--message-format" "json-render-diagnostics" "--manifest-path" "/tmp/pip-install-9ncbhy4u/pydantic-core_53401a52cce74fab9860bde9c1518d21/Cargo.toml" "--release" "--lib" "--crate-type" "cdylib"`
          Error: command ['maturin', 'pep517', 'build-wheel', '-i', '/home/tcaswell/.virtualenvs/cp314-clang/bin/python3', '--compatibility', 'off'] returned non-zero exit status 1
          [end of output]
    
      note: This error originates from a subprocess, and is likely not a problem with pip.
      ERROR: Failed building wheel for pydantic-core
    

    which I expect is due to the same root cause (PEP 649 and annotations being lazy).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug V2Bug related to Pydantic V2pendingIs unconfirmed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions