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: pydantic 2.10.x breaking change #1095

Merged
18 changes: 4 additions & 14 deletions beanie/odm/utils/pydantic.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
from typing import Any, Type

import pydantic
from packaging.specifiers import SpecifierSet
from packaging.version import Version
from pydantic import BaseModel


def is_version_valid(version, requirement):
# Parse the requirement as a SpecifierSet
specifiers = SpecifierSet(requirement)
# Parse the version as a Version
v = Version(version)
# Check if the version satisfies the specifiers
return v in specifiers


IS_PYDANTIC_V2 = is_version_valid(pydantic.VERSION, ">=2")
IS_PYDANTIC_V2_10 = is_version_valid(pydantic.VERSION, ">=2.10")
IS_PYDANTIC_V2 = int(pydantic.VERSION.split(".")[0]) >= 2
IS_PYDANTIC_V2_10 = (
IS_PYDANTIC_V2 and int(pydantic.VERSION.split(".")[1]) >= 10
) or int(pydantic.VERSION.split(".")[0]) > 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this "or" part. Any other major Pydantic version would not necessarily be compatible with Beanie and I think we should not bet on this.
Lets make this check do what it says in the name, to explicitly check for Pydantic v2.10.x (or above, constrained to v2).


if IS_PYDANTIC_V2:
from pydantic import TypeAdapter
Expand Down