Bug 2259626 - python-pydantic-core fails to build with Python 3.13: generate_self_schema.py incompatibility
Summary: python-pydantic-core fails to build with Python 3.13: generate_self_schema.py...
Keywords:
Status: NEW
Alias: None
Product: Fedora
Classification: Fedora
Component: python-pydantic-core
Version: 40
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Maxwell G
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks: PYTHON3.13 2256753
TreeView+ depends on / blocked
 
Reported: 2024-01-22 13:16 UTC by Karolina Surma
Modified: 2024-05-16 09:51 UTC (History)
7 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: Bug
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github PyO3 pyo3 issues 3555 0 None closed How to keep users safe regarding alpha Pythons? 2024-04-21 19:57:43 UTC
Github pydantic pydantic-core issues 1175 0 None open [Heads up] test_invalid_regex fails with Python 3.13.0a3 (re.Error renamed to PatternError) 2024-01-31 12:21:12 UTC

Description Karolina Surma 2024-01-22 13:16:17 UTC
python-pydantic-core fails to build with Python 3.13.03.

________________________ test_invalid_regex[python-re] _________________________

engine = 'python-re'

    @pytest.mark.parametrize('engine', [None, 'rust-regex', 'python-re'])
    def test_invalid_regex(engine):
        # TODO uncomment and fix once #150 is done
        # with pytest.raises(SchemaError) as exc_info:
        #     SchemaValidator({'type': 'str', 'pattern': 123})
        # assert exc_info.value.args[0] == (
        #     'Error building "str" validator:\n  TypeError: \'int\' object cannot be converted to \'PyString\''
        # )
        with pytest.raises(SchemaError) as exc_info:
            SchemaValidator(core_schema.str_schema(pattern='(abc', regex_engine=engine))
    
        if engine is None or engine == 'rust-regex':
            assert exc_info.value.args[0] == (
                'Error building "str" validator:\n'
                '  SchemaError: regex parse error:\n'
                '    (abc\n'
                '    ^\n'
                'error: unclosed group'
            )
        elif engine == 'python-re':
>           assert exc_info.value.args[0] == (
                'Error building "str" validator:\n  error: missing ), unterminated subpattern at position 0'
            )
E           assert 'Error buildi...at position 0' == 'Error buildi...at position 0'
E               Error building "str" validator:
E             -   error: missing ), unterminated subpattern at position 0
E             +   PatternError: missing ), unterminated subpattern at position 0
E             ?   ++++ +++

tests/validators/test_string.py:190: AssertionError
=========================== short test summary info ============================
FAILED tests/validators/test_string.py::test_invalid_regex[python-re] - asser...

https://docs.python.org/3.13/whatsnew/3.13.html

For the build logs, see:
https://copr-be.cloud.fedoraproject.org/results/@python/python3.13/fedora-rawhide-x86_64/06935469-python-pydantic-core/

For all our attempts to build python-pydantic-core with Python 3.13, see:
https://copr.fedorainfracloud.org/coprs/g/python/python3.13/package/python-pydantic-core/

Testing and mass rebuild of packages is happening in copr.
You can follow these instructions to test locally in mock if your package builds with Python 3.13:
https://copr.fedorainfracloud.org/coprs/g/python/python3.13/

Let us know here if you have any questions.

Python 3.13 is planned to be included in Fedora 41.
To make that update smoother, we're building Fedora packages with all pre-releases of Python 3.13.
A build failure prevents us from testing all dependent packages (transitive [Build]Requires),
so if this package is required a lot, it's important for us to get it fixed soon.

We'd appreciate help from the people who know this package best,
but if you don't want to work on this now, let us know so we can try to work around it on our side.

Comment 1 Aoife Moloney 2024-02-15 23:11:42 UTC
This bug appears to have been reported against 'rawhide' during the Fedora Linux 40 development cycle.
Changing version to 40.

Comment 2 Ben Beasley 2024-04-21 19:57:44 UTC
Now that we have PyO3 0.21.1, this is now failing due to PyO3 explicitly rejecting Python 3.13 as unsupported:

  error: failed to run custom build command for `pyo3-ffi v0.21.1`

  Caused by:
    process didn't exit successfully: `/builddir/build/BUILD/pydantic-core-2.18.1/target/release/build/pyo3-ffi-e2fafa3566aa8c2d/build-script-build` (exit status: 1)
    --- stdout
    cargo:rerun-if-env-changed=PYO3_CROSS
    cargo:rerun-if-env-changed=PYO3_CROSS_LIB_DIR
    cargo:rerun-if-env-changed=PYO3_CROSS_PYTHON_VERSION
    cargo:rerun-if-env-changed=PYO3_CROSS_PYTHON_IMPLEMENTATION
    cargo:rerun-if-env-changed=PYO3_PRINT_CONFIG
    cargo:rerun-if-env-changed=PYO3_USE_ABI3_FORWARD_COMPATIBILITY

    --- stderr
    error: the configured Python interpreter version (3.13) is newer than PyO3's maximum supported version (3.12)
    = help: please check if an updated version of PyO3 is available. Current version: 0.21.1
    = help: set PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 to suppress this check and build anyway using the stable ABI

See https://bugzilla.redhat.com/show_bug.cgi?id=2256753#c1 and also https://github.com/PyO3/pyo3/issues/3555.

We should be able to work around this by setting the environment variable PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1. I suggest doing that only in a [DO NOT MERGE] PR – which should allow a build to be at least attempted in the COPR – and only setting it in the rawhide branch if Python 3.13 reaches Rawhide before PyO3 supports it.

If I set PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1, I get

  error[E0425]: cannot find function, tuple struct or tuple variant `PyUnicode_New` in module `pyo3::ffi`
     --> /usr/share/cargo/registry/jiter-0.2.1/src/py_string_cache.rs:199:26
      |
  199 |       let ptr = pyo3::ffi::PyUnicode_New(s.len() as isize, 127);
      |                            ^^^^^^^^^^^^^ help: a function with a similar name exists: `PySlice_New`
      |
     ::: /usr/share/cargo/registry/pyo3-ffi-0.21.1/src/sliceobject.rs:50:5
      |
  50  | /     pub fn PySlice_New(
  51  | |         start: *mut PyObject,
  52  | |         stop: *mut PyObject,
  53  | |         step: *mut PyObject,
  54  | |     ) -> *mut PyObject;
      | |______________________- similarly named function `PySlice_New` defined here

  error[E0425]: cannot find function, tuple struct or tuple variant `PyUnicode_KIND` in module `pyo3::ffi`
     --> /usr/share/cargo/registry/jiter-0.2.1/src/py_string_cache.rs:201:33
      |
  201 |       debug_assert_eq!(pyo3::ffi::PyUnicode_KIND(ptr), pyo3::ffi::PyUnicode_1BYTE_KIND);
      |                                   ^^^^^^^^^^^^^^ help: a function with a similar name exists: `PyUnicode_Find`
      |
     ::: /usr/share/cargo/registry/pyo3-ffi-0.21.1/src/unicodeobject.rs:299:5
      |
  299 | /     pub fn PyUnicode_Find(
  300 | |         str: *mut PyObject,
  301 | |         substr: *mut PyObject,
  302 | |         start: Py_ssize_t,
  303 | |         end: Py_ssize_t,
  304 | |         direction: c_int,
  305 | |     ) -> Py_ssize_t;
      | |___________________- similarly named function `PyUnicode_Find` defined here

  error[E0425]: cannot find value `PyUnicode_1BYTE_KIND` in module `pyo3::ffi`
     --> /usr/share/cargo/registry/jiter-0.2.1/src/py_string_cache.rs:201:65
      |
  201 |     debug_assert_eq!(pyo3::ffi::PyUnicode_KIND(ptr), pyo3::ffi::PyUnicode_1BYTE_KIND);
      |                                                                 ^^^^^^^^^^^^^^^^^^^^ not found in `pyo3::ffi`

  error[E0425]: cannot find function, tuple struct or tuple variant `PyUnicode_DATA` in module `pyo3::ffi`
     --> /usr/share/cargo/registry/jiter-0.2.1/src/py_string_cache.rs:202:31
      |
  202 |       let data_ptr = pyo3::ffi::PyUnicode_DATA(ptr).cast();
      |                                 ^^^^^^^^^^^^^^ help: a function with a similar name exists: `PyUnicode_Find`
      |
     ::: /usr/share/cargo/registry/pyo3-ffi-0.21.1/src/unicodeobject.rs:299:5
      |
  299 | /     pub fn PyUnicode_Find(
  300 | |         str: *mut PyObject,
  301 | |         substr: *mut PyObject,
  302 | |         start: Py_ssize_t,
  303 | |         end: Py_ssize_t,
  304 | |         direction: c_int,
  305 | |     ) -> Py_ssize_t;
      | |___________________- similarly named function `PyUnicode_Find` defined here

  For more information about this error, try `rustc --explain E0425`.
  error: could not compile `jiter` (lib) due to 4 previous errors

so either way I think we aren’t going to be able to do much here until PyO3 is ready for Python 3.13.

Comment 3 Karolina Surma 2024-04-22 07:59:14 UTC
I became aware of this isse last week and tried to mitigate it via skipping version check in RPM builds for both rust-pyo3-ffi packages: https://src.fedoraproject.org/rpms/rust-pyo3-ffi/pull-request/2 - feel free to comment on the PR.

Comment 4 Fabio Valentini 2024-04-22 09:54:03 UTC
I'm building pyo3-ffi with the compatibility check disabled right now, so this change in pydantic-core should become unnecessary (assuming that Python 3.13 doesn't break PyO3).

Comment 5 Karolina Surma 2024-05-16 09:51:15 UTC
With Python 3.13.0b1 the issue is different, already reported upstream: https://github.com/pydantic/pydantic-core/issues/1292


Note You need to log in before you can comment on or make changes to this bug.