Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Pydantic 1.X doesn't work with Python 3.12.4 #9607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
6 of 15 tasks
k4nar opened this issue Jun 7, 2024 · 5 comments
Closed
6 of 15 tasks

Pydantic 1.X doesn't work with Python 3.12.4 #9607

k4nar opened this issue Jun 7, 2024 · 5 comments
Labels
bug V1 Bug related to Pydantic V1.X pending Is unconfirmed

Comments

@k4nar
Copy link
Contributor

k4nar commented Jun 7, 2024

Initial Checks

  • I have searched GitHub for a duplicate issue and I'm sure this is something new
  • I have searched Google & StackOverflow for a solution and couldn't find anything
  • I have read and followed the docs and still think this is a bug
  • I am confident that the issue is with pydantic (not my code, or another library in the ecosystem like FastAPI or mypy)

Description

Using Pydantic 1.10.15 with Python 3.12.4 throws the following error:

TypeError: ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard'

This looks very similar to this issue fixed recently in typeguard by this PR: agronholm/typeguard#460.

Example Code

I initially discovered the error when trying to import fastapi (it was failing here), but I was able to reproduce by defining a model containing a type which doesn't exist yet:

Python 3.12.4 (main, Jun  7 2024, 19:37:37) [GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydantic
>>> class Foo(pydantic.BaseModel):
...     foo: "Nope"
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.12/site-packages/pydantic/main.py", line 286, in __new__
    cls.__try_update_forward_refs__()
  File "/usr/local/lib/python3.12/site-packages/pydantic/main.py", line 807, in __try_update_forward_refs__
    update_model_forward_refs(cls, cls.__fields__.values(), cls.__config__.json_encoders, localns, (NameError,))
  File "/usr/local/lib/python3.12/site-packages/pydantic/typing.py", line 554, in update_model_forward_refs
    update_field_forward_refs(f, globalns=globalns, localns=localns)
  File "/usr/local/lib/python3.12/site-packages/pydantic/typing.py", line 520, in update_field_forward_refs
    field.type_ = evaluate_forwardref(field.type_, globalns, localns or None)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/pydantic/typing.py", line 66, in evaluate_forwardref
    return cast(Any, type_)._evaluate(globalns, localns, set())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard'
>>>

Python, Pydantic & OS Version

pydantic version: 1.10.15
            pydantic compiled: False
                 install path: /usr/local/lib/python3.12/site-packages/pydantic
               python version: 3.12.4 (main, Jun  7 2024, 19:37:37) [GCC 10.2.1 20210110]
                     platform: Linux-6.9.3-arch1-1-x86_64-with-glibc2.31
     optional deps. installed: ['typing-extensions']

Affected Components

@k4nar k4nar added bug V1 Bug related to Pydantic V1.X pending Is unconfirmed labels Jun 7, 2024
@k4nar
Copy link
Contributor Author

k4nar commented Jun 7, 2024

Note: I don't reproduce with Pydantic 2. Too bad it happens right when I was working on the migration of my project 😅 .

@andersskog
Copy link

Seeing the same issue. In our case we are using pydantic 2.7.1, but are importing mergepythonclient which relies on V1.

@znruss
Copy link

znruss commented Jun 8, 2024

Seconded, this is an issue that specifically cropped up moving from python 3.12.3 to python 3.12.4. It also affects pydantic.v1 within pydantic==2.7.3

@ellyx13
Copy link

ellyx13 commented Jun 8, 2024

My solution was to downgrade python to version 3.12.3 and it worked properly

@sydney-runkle
Copy link
Contributor

Closed by #9612

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