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

fix: handle missing pydantic-core corner case #115

Merged
merged 2 commits into from
May 10, 2024

Conversation

elventear
Copy link
Contributor

@elventear elventear commented May 10, 2024

This change handles a corner case where pydantic is installed in the environment but pydantic-core is missing. The current code assumes that if pydantic is importable, then pydantic is available, but the access of pydantic.BaseModel does a lazy import of pydantic-core which is not handled, crashing the application that is using cappa.

To handle the issue, BaseModel is imported eagerly during the detection step, which will throw an error when pydantic-core is not available.

I have observed this in the wild, where I am not using pydantic with cappa at all, nor it is one of my direct dependencies, but it is still being pulled transitively from other sources, crashing my application. This issue surfaced with https://github.com/DanCardin/cappa/releases/tag/v0.19.0.

@DanCardin
Copy link
Owner

DanCardin commented May 10, 2024

I'm happy to accept this change, as I see no harm it in.

But besides that, I wonder if you're befallen by something like python-poetry/poetry#9266. If you have pydantic you should have pydantic_core. I recently found myself hitting related-sounding issues where the lock wasn't installing required transitive dependencies (including pydantic_core).

(Not that it's necessarily relevant to you that pydantic is broken, if you're not using it. Just that you might have other issues, if this is the same problem I encountered)

@DanCardin DanCardin merged commit ee024c2 into DanCardin:main May 10, 2024
7 checks passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants