Skip to content

Commit

Permalink
Allow Pydantic >= 2.5.3 (#1388)
Browse files Browse the repository at this point in the history
* Allow Pydantic >= 2.5.3

* remove types-pkg-resources

it was yanked on pypi because it's obsoleted by types-setuptools.
but pkg_resources is typed in recent setuptools, so we don't need a
types package at all

* poetry lock

* fix type annotation for 2.8.2

create_schema_validator now returns SchemaValidator | PluggableSchemaValidator

* allow pydantic up to 2.8 for now

* accept new error message in test

* fix binary test that was corrupted

* bump security deps to avoid errors in codefactor

* unify poetry versions and bump

---------

Co-authored-by: collerek <[email protected]>
  • Loading branch information
camillol and collerek authored Dec 5, 2024
1 parent 6be6136 commit a1f6e57
Show file tree
Hide file tree
Showing 12 changed files with 1,188 additions and 1,560 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Install Poetry
uses: snok/[email protected]
with:
version: 1.4.2
version: 1.8.4
virtualenvs-create: false

- name: Poetry details
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install poetry==1.4.1
python -m pip install poetry==1.8.4
poetry install --extras "all"
env:
POETRY_VIRTUALENVS_CREATE: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install Poetry
uses: snok/[email protected]
with:
version: 1.4.2
version: 1.8.4
virtualenvs-create: false

- name: Poetry details
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install Poetry
uses: snok/[email protected]
with:
version: 1.4.1
version: 1.8.4
virtualenvs-create: true
virtualenvs-in-project: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Install Poetry
uses: snok/[email protected]
with:
version: 1.4.2
version: 1.8.4
virtualenvs-create: false

- name: Poetry details
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
python-version: 3.11
- name: Install dependencies
run: |
python -m pip install poetry==1.4.2
python -m pip install poetry==1.8.4
poetry install --extras "all"
env:
POETRY_VIRTUALENVS_CREATE: false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/type-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Install Poetry
uses: snok/[email protected]
with:
version: 1.4.2
version: 1.8.4
virtualenvs-create: false

- name: Poetry details
Expand Down
9 changes: 7 additions & 2 deletions ormar/models/mixins/save_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
cast,
)

from pydantic.plugin._schema_validator import create_schema_validator
from pydantic.plugin._schema_validator import (
PluggableSchemaValidator,
create_schema_validator,
)
from pydantic_core import CoreSchema, SchemaValidator

import ormar # noqa: I100, I202
Expand All @@ -36,7 +39,9 @@ class SavePrepareMixin(RelationMixin, AliasMixin):
_json_fields: Set[str]
_bytes_fields: Set[str]
__pydantic_core_schema__: CoreSchema
__ormar_fields_validators__: Optional[Dict[str, SchemaValidator]]
__ormar_fields_validators__: Optional[
Dict[str, SchemaValidator | PluggableSchemaValidator]
]

@classmethod
def prepare_model_to_save(cls, new_kwargs: dict) -> dict:
Expand Down
2,709 changes: 1,166 additions & 1,543 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ classifiers = [
[tool.poetry.dependencies]
python = "^3.8.0"
databases = "^0.7.0"
pydantic = "v2.5.3"
pydantic = ">=2.5.3,<2.9.0"
SQLAlchemy = "^1.4.42"
cryptography = { version = ">=41.0.3,<43.0.0", optional = true }
# Async database drivers
Expand Down Expand Up @@ -88,7 +88,7 @@ pytest = ">=7.4.4,<9.0.0"
pytest-cov = ">=4,<6"
codecov = "^2.1.13"
pytest-asyncio = ">=0.21,<0.24"
fastapi = ">=0.109.1,<0.112.0"
fastapi = ">=0.109.1,<0.115.6"

black = "^24.1.0"
ruff = ">=0.5.1,<0.5.2"
Expand All @@ -102,7 +102,6 @@ types-enum34 = "^1.1.1"
types-cryptography = "^3.3.23"
types-orjson = "^3.6.1"
types-aiofiles = "^23.2.0"
types-pkg-resources = "^0.1.3"
types-requests = "^2.31.0"
types-toml = "^0.10.8"

Expand Down
6 changes: 2 additions & 4 deletions tests/test_fastapi/test_binary_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ async def test_read_main():
)
assert response.status_code == 200
response = await client.get("/things")
assert response.json()[0]["bt"] == blob3.decode()
resp_json = response.json()
resp_json[0]["bt"] = resp_json[0]["bt"].encode()
thing = BinaryThing(**resp_json[0])
assert response.json()[0]["bt"] == base64.b64encode(blob3).decode()
thing = BinaryThing(**response.json()[0])
assert thing.__dict__["bt"] == blob3
assert thing.bt == base64.b64encode(blob3).decode()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def test_constraints():

with pytest.raises(
ValidationError,
match="The email address is not valid. It must have exactly one @-sign",
match=(
r"The email address is not valid. It must have exactly one @-sign|"
r"An email address must have an @-sign"
),
):
User(email="wrong")

Expand Down

0 comments on commit a1f6e57

Please sign in to comment.