From 7eba5ef20dc3502ad0617d7a423fa16ae9517feb Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Thu, 28 Sep 2023 11:27:23 +0200 Subject: [PATCH] update pydantic for breaking changes --- .pre-commit-config.yaml | 2 +- pyproject.toml | 2 +- titiler/pgstac/model.py | 12 +++--------- titiler/pgstac/settings.py | 4 ++-- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8df89dc..03a9f39 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -31,4 +31,4 @@ repos: additional_dependencies: - types-cachetools - types-attrs - - pydantic~=2.0 + - pydantic>=2.4 diff --git a/pyproject.toml b/pyproject.toml index e27c2b4..69c0b22 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,7 @@ dependencies = [ "titiler.core>=0.14.0,<0.15", "titiler.mosaic>=0.14.0,<0.15", "geojson-pydantic~=1.0", - "pydantic~=2.0", + "pydantic>=2.4,<3.0", "pydantic-settings~=2.0", ] dynamic = ["version"] diff --git a/titiler/pgstac/model.py b/titiler/pgstac/model.py index 0f4282d..f36e0de 100644 --- a/titiler/pgstac/model.py +++ b/titiler/pgstac/model.py @@ -9,13 +9,7 @@ from geojson_pydantic.geometries import Geometry from geojson_pydantic.types import BBox -from pydantic import ( - BaseModel, - Field, - FieldValidationInfo, - field_validator, - model_validator, -) +from pydantic import BaseModel, Field, ValidationInfo, field_validator, model_validator from typing_extensions import Annotated from titiler.core.resources.enums import MediaType @@ -95,7 +89,7 @@ def validate_datetime(cls, v): return v @field_validator("intersects") - def validate_spatial(cls, v: Optional[Geometry], info: FieldValidationInfo): + def validate_spatial(cls, v: Optional[Geometry], info: ValidationInfo): """Make sure bbox is not used with Intersects.""" if v and info.data["bbox"]: raise ValueError("intersects and bbox parameters are mutually exclusive") @@ -200,7 +194,7 @@ class Context(BaseModel): matched: Optional[int] = None @field_validator("limit") - def validate_limit(cls, v, info: FieldValidationInfo): + def validate_limit(cls, v, info: ValidationInfo): """validate limit.""" if info.data["returned"] > v: raise ValueError( diff --git a/titiler/pgstac/settings.py b/titiler/pgstac/settings.py index c6923ad..ede88a0 100644 --- a/titiler/pgstac/settings.py +++ b/titiler/pgstac/settings.py @@ -5,8 +5,8 @@ from pydantic import ( Field, - FieldValidationInfo, PostgresDsn, + ValidationInfo, field_validator, model_validator, ) @@ -68,7 +68,7 @@ class PostgresSettings(BaseSettings): model_config = {"env_file": ".env", "extra": "ignore"} @field_validator("database_url", mode="before") - def assemble_db_connection(cls, v: Optional[str], info: FieldValidationInfo) -> Any: + def assemble_db_connection(cls, v: Optional[str], info: ValidationInfo) -> Any: """Validate database config.""" if isinstance(v, str): return v