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

AttributeError with pydantic 2.10.0 & 2.10.1 (fixed in 2.10.2) #411

Closed
twhalm opened this issue Nov 21, 2024 · 11 comments
Closed

AttributeError with pydantic 2.10.0 & 2.10.1 (fixed in 2.10.2) #411

twhalm opened this issue Nov 21, 2024 · 11 comments

Comments

@twhalm
Copy link

twhalm commented Nov 21, 2024

With pydantic v2.10.0, importing pyairtable causes the following error:

Exception has occurred: AttributeError
partially initialized module 'pyairtable' has no attribute 'api' (most likely due to a circular import)
  File "file.py", line 2, in <module>
    from pyairtable import Api
AttributeError: partially initialized module 'pyairtable' has no attribute 'api' (most likely due to a circular import)

This error does not occur with earlier versions of pydantic.

@shaunagm
Copy link

shaunagm commented Nov 21, 2024

We're getting the same error.

Edit: it looks like this is an issue with Pydantic 2.10 which introduced a number of regressions being actively worked on that have bubbled up to pyairtable

@JasonCrowe
Copy link

I backed off to 2.9 and it's working.

@Eagles0607
Copy link

Backing off to 2.9 worked for me as well.

@sungmincs
Copy link

Pydantic 2.10.1 still doesn't fix this issue.

@Viicos
Copy link

Viicos commented Nov 24, 2024

This should be fixed in 2.10.2, coming next week. The reason you are getting this issue is because the following _api private field annotation:

class RestfulModel(AirtableModel):
"""
Base model for any data structures that wrap around a REST API endpoint.
Subclasses can pass a number of keyword arguments to control serialization behavior:
* ``url=``: format string for building the URL to be used when saving changes to this model.
"""
__url_pattern: ClassVar[str] = ""
_api: "pyairtable.api.api.Api" = pydantic.PrivateAttr()

failed to be evaluated in Pydantic <= 2.9. In 2.10, we refactored our forward annotation evaluation logic to be more correct, meaning it does evaluate the forward annotation as expected. However, this leads to a circular import because the pyairtable.api.api module is already in the process of being imported when this forward annotation is evaluated.

2.10.2 will include a fix to not evaluate forward annotations for private fields, because we don't make use of the annotation any way.

@mesozoic
Copy link
Collaborator

Thanks @Viicos for keeping us updated, and for working toward a patch to fix the issue. 🙌

In the meantime I've opened #412 in case anyone out there has ideas for how to remove the circular dependencies caused by type annotations in this library.

@Viicos
Copy link

Viicos commented Nov 24, 2024

In the meantime I've opened #412 in case anyone out there has ideas for how to remove the circular dependencies caused by type annotations in this library.

Note that as long as these circular issues happens in private attributes, it shouldn't be an issue anymore in the next patch release. But yeah, if they are used for "normal" Pydantic fields, this is going to be an issue.

@coronarita1991
Copy link

I got a same error as above while importing pyairtable, and solved with downgrading pydantic with 2.9.2. After solving issue I could reach this post. Anyway, thanks.

@LouisMonierSpark
Copy link

Super painful issue. This should be prioritized asap.

@Viicos
Copy link

Viicos commented Nov 26, 2024

2.10.2 is now released, and fixes the issue.

@mesozoic
Copy link
Collaborator

Thank you for the fix, @Viicos! I'll resolve this issue now.

Note that as long as these circular issues happens in private attributes, it shouldn't be an issue anymore in the next patch release. But yeah, if they are used for "normal" Pydantic fields, this is going to be an issue.

Heard! I don't foresee us adding any more things like this, but it'll still be an interesting mental exercise to rethink the dependency graph within the library. Thanks again for your help.

@mesozoic mesozoic changed the title Import conflict with pydantic 2.10.0 AttributeError with pydantic 2.10.0 & 2.10.1 (fixed in pydantic 2.10.2) Nov 28, 2024
@mesozoic mesozoic pinned this issue Nov 28, 2024
@mesozoic mesozoic changed the title AttributeError with pydantic 2.10.0 & 2.10.1 (fixed in pydantic 2.10.2) AttributeError with pydantic 2.10.0 & 2.10.1 (fixed in 2.10.2) Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants