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

Work around issue in Pydantic v1.10.16 #439

Closed
wants to merge 2 commits into from

Conversation

jherland
Copy link
Member

Minor workaround to fix issue #438.

Upstream Pydantic issue: pydantic/pydantic#9656

Commits:

  • test_settings: Workaround issue in Pydantic v1.10.16
  • noxfile.py: Rerun poetry export if reqs_from_poetry.txt is missing

jherland added 2 commits June 13, 2024 16:04
Pydantic v1.10.16 introduces the `pydantic.v1` namespace (adopted from
Pydantic v2) in order to make migrations from Pydantic v1 to v2 easier.

However, as detailed in issue #438 (and the corresponding upstream issue
pydantic/pydantic#9656), in Pydantic v1.10.16
(when run on Python 3.12) objects imported via the `pydantic.v1`
namespace are not identical (in the `id(...)` sense) to the
corresponding objects imported via the regular `pydantic` namespace.

This causes problem when we want to catch exceptions raised by Pydantic:
the actual exception class being raised is not identical to the one we
`import` from `pydantic.v1.<something>`.

The workaround applied here is to ensure that we never import from the
`pydantic.v1` namespace when we're running on Pydantic v1.
I've run into a few cases where I've needed to recreate the Nox
virtualenv, and I've simply deleted the corresponding
reqs_from_poetry.txt file to ensure that everything is regenerated from
scratch. However, the test in noxfile.py only checks for the associated
.hash digest file, and then promptly fails when it tries to reuse the
missing file.

Add another clause to the if-condition to fix this.
@jherland jherland self-assigned this Jun 13, 2024
@jherland jherland linked an issue Jun 13, 2024 that may be closed by this pull request
@jherland
Copy link
Member Author

There is an ongoing PR to fix the upstream issue: pydantic/pydantic#9660

If that ends up being merged and released soon, we can probably drop this PR.

@jherland
Copy link
Member Author

jherland commented Jul 2, 2024

Pydantic v1.10.17 does not trigger the same issue, and this workaround is considered unnecessary.

@jherland jherland closed this Jul 2, 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

Successfully merging this pull request may close these issues.

Test regressions with Pydantic 1.10.16
1 participant