Skip to content
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

TypeError: issubclass() arg 1 must be a class when upgrading to 2.5 #390

Closed
antazoey opened this issue Sep 10, 2024 · 15 comments · Fixed by #392
Closed

TypeError: issubclass() arg 1 must be a class when upgrading to 2.5 #390

antazoey opened this issue Sep 10, 2024 · 15 comments · Fixed by #392
Assignees
Labels
bug Something isn't working

Comments

@antazoey
Copy link

antazoey commented Sep 10, 2024

Hello,

Ever since 2.5 was released, all of our CI/CD fails on Python 3.9 and 3.10 with the following error:

../../virtualenvs/ape_310/lib/python3.10/site-packages/pydantic_settings/sources.py:771: in _field_is_complex
    if self.field_is_complex(field):
../../virtualenvs/ape_310/lib/python3.10/site-packages/pydantic_settings/sources.py:276: in field_is_complex
    return _annotation_is_complex(field.annotation, field.metadata)
../../virtualenvs/ape_310/lib/python3.10/site-packages/pydantic_settings/sources.py:2118: in _annotation_is_complex
    if isinstance(annotation, type) and issubclass(annotation, RootModel):
../../.pyenv/versions/3.10.0/lib/python3.10/abc.py:123: in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)

We are using a config setup like the following (simple reproduction):

from pydantic_settings import BaseSettings

class BaseConfig(BaseSettings):
    pass

class Exclusion(BaseConfig):
    name: str = "*"

class Wrapper(BaseConfig):
    exclude: list[Exclusion] = []

class MyConfig(BaseConfig):
    coverage: Wrapper = Wrapper()

cfg = MyConfig()

^ When I run the above script, I basically get the same error as ours. I tried to make it as simple as possible.

@shedar
Copy link

shedar commented Sep 10, 2024

I'm having the same issue with python3.10 and pydantic_settings 2.5.0. This line fails for any list[XXX] fields, since

>>> from pydantic.root_model import RootModel

>>> isinstance(list[int], type)
True

>>> issubclass(list[int], RootModel)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/python@3.10/3.10.14/Frameworks/Python.framework/Versions/3.10/lib/python3.10/abc.py", line 123, in __subclasscheck__
    return _abc_subclasscheck(cls, subclass)
TypeError: issubclass() arg 1 must be a class

@hramezani
Copy link
Member

Thanks for reporting this issue. I try to fix the problem and prepare a new release soon.

@hramezani
Copy link
Member

hramezani commented Sep 10, 2024

Just made a quick fix #392

Can you confirm that the fix is correct?

@hramezani hramezani added bug Something isn't working and removed unconfirmed labels Sep 10, 2024
@shedar
Copy link

shedar commented Sep 10, 2024

I can confirm that it works on my config.
But I don't fully understand the condition, so I don't know if this change has any undesired side effects.

@hramezani
Copy link
Member

Thanks @shedar for checking. It shouldn't effect other things.

I will wait until tomorrow and then will prepare a patch release.

@hramezani
Copy link
Member

pydantic-settings 2.5.1 which contain the fix has been released. Thanks for reporting!

@pgiraud
Copy link

pgiraud commented Sep 11, 2024

It looks like the simple example provided by @antazoey is still failing with pydantic-settings 2.5.1 and python 3.9 or 3.10.

@pgiraud
Copy link

pgiraud commented Sep 11, 2024

The example can even be simplified to:

from pydantic_settings import BaseSettings

class Bar(BaseSettings):
    foo: list[str] = []

cfg = Bar()

This fails with TypeError: issubclass() arg 1 must be a class error on 3.9 and 3.10.

@hramezani
Copy link
Member

I created the second patch to fix the problem.
I keep the PR open for testing. Then will release a new patch.

Thanks all for reporting!

@hramezani
Copy link
Member

pydantic-settings 2.5.2 has been released

@davidwaroquiers
Copy link

Thanks for this having looked at this quickly @hramezani. It also affected some of the software stack we are using. I will check if 2.5.2 indeed solves our issues. Maybe versions 2.5.0 and 2.5.1 could/should be yanked on pypi ?

@hramezani
Copy link
Member

Thanks for this having looked at this quickly @hramezani. It also affected some of the software stack we are using. I will check if 2.5.2 indeed solves our issues. Maybe versions 2.5.0 and 2.5.1 could/should be yanked on pypi ?

Thanks @davidwaroquiers for confirming. I think we don't need to yank the previous version

@davidwaroquiers
Copy link

Hi @hramezani,

Seems that 2.5.2 indeed solves our issues.

Thanks again,

Best,

David

@antazoey
Copy link
Author

Confirmed 2.5.2 fixed it for us.

@hramezani
Copy link
Member

Thasnk all for reporting and helping to resolve the bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants