diff --git a/dev-requirements.txt b/dev-requirements.txt index 95175f8a..be8de496 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -2,6 +2,8 @@ # uv pip compile --extra dev pyproject.toml --output-file dev-requirements.txt alabaster==1.0.0 # via sphinx +annotated-doc==0.0.4 + # via fastapi annotated-types==0.7.0 # via pydantic anyio==4.9.0 @@ -45,12 +47,6 @@ click==8.2.1 # uvicorn codespell==2.4.1 # via labthings-fastapi (pyproject.toml) -colorama==0.4.6 - # via - # click - # pytest - # sphinx - # uvicorn coverage==7.9.2 # via pytest-cov cssutils==2.11.1 @@ -83,7 +79,7 @@ exceptiongroup==1.3.0 # via # anyio # pytest -fastapi==0.116.1 +fastapi==0.135.1 # via labthings-fastapi (pyproject.toml) fastapi-cli==0.0.8 # via fastapi @@ -169,8 +165,6 @@ natsort==8.4.0 # via domdf-python-tools numpy==2.2.6 # via labthings-fastapi (pyproject.toml) -orjson==3.11.0 - # via fastapi packaging==25.0 # via # pytest @@ -187,14 +181,14 @@ pluggy==1.6.0 # pytest-cov pycodestyle==2.14.0 # via flake8 -pydantic==2.10.6 +pydantic==2.12.5 # via # labthings-fastapi (pyproject.toml) # fastapi # fastapi-cloud-cli # pydantic-extra-types # pydantic-settings -pydantic-core==2.27.2 +pydantic-core==2.41.5 # via pydantic pydantic-extra-types==2.10.5 # via fastapi @@ -355,10 +349,11 @@ typing-extensions==4.14.1 # typer # typing-inspection # uvicorn -typing-inspection==0.4.1 - # via pydantic-settings -ujson==5.10.0 - # via fastapi +typing-inspection==0.4.2 + # via + # fastapi + # pydantic + # pydantic-settings urllib3==2.5.0 # via # requests @@ -369,6 +364,8 @@ uvicorn==0.35.0 # fastapi # fastapi-cli # fastapi-cloud-cli +uvloop==0.22.1 + # via uvicorn watchfiles==1.1.0 # via uvicorn webencodings==0.5.1 diff --git a/pyproject.toml b/pyproject.toml index ecd49c92..51eab323 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,13 +13,13 @@ classifiers = [ "Operating System :: OS Independent", ] dependencies = [ - "pydantic ~= 2.10.6", + "pydantic ~= 2.12", "numpy>=1.20", "jsonschema", "typing_extensions", "anyio ~=4.0", "httpx", - "fastapi[all]>=0.115.0", + "fastapi[all]~=0.135.0", "zeroconf >=0.28.0", ] diff --git a/src/labthings_fastapi/outputs/blob.py b/src/labthings_fastapi/outputs/blob.py index 03dc570a..9df4cd92 100644 --- a/src/labthings_fastapi/outputs/blob.py +++ b/src/labthings_fastapi/outputs/blob.py @@ -614,7 +614,7 @@ def __get_pydantic_core_schema__( """ return core_schema.no_info_wrap_validator_function( cls._validate, - BlobModel.__get_pydantic_core_schema__(BlobModel, handler), + BlobModel.__pydantic_core_schema__, serialization=core_schema.wrap_serializer_function_ser_schema( cls._serialize, is_field_serializer=False, diff --git a/src/labthings_fastapi/utilities/__init__.py b/src/labthings_fastapi/utilities/__init__.py index 13173b4b..f26fddc5 100644 --- a/src/labthings_fastapi/utilities/__init__.py +++ b/src/labthings_fastapi/utilities/__init__.py @@ -6,7 +6,6 @@ from weakref import WeakSet from pydantic import BaseModel, ConfigDict, Field, RootModel, create_model from pydantic.dataclasses import dataclass -from pydantic_core import SchemaError from labthings_fastapi.exceptions import UnsupportedConstraintError from .introspection import EmptyObject @@ -129,7 +128,7 @@ def wrap_plain_types_in_rootmodel( :raises UnsupportedConstraintError: if constraints are provided for an unsuitable type, for example `allow_inf_nan` for an `int` property, or any constraints for a `BaseModel` subclass. - :raises SchemaError: if other errors prevent Pydantic from creating a schema + :raises RuntimeError: if other errors prevent Pydantic from creating a schema for the generated model. """ try: # This needs to be a `try` as basic types are not classes @@ -148,13 +147,9 @@ def wrap_plain_types_in_rootmodel( root=(model, Field(**constraints)), __base__=LabThingsRootModelWrapper, ) - except SchemaError as e: - for error in e.errors(): - if error["loc"][-1] in constraints: - key = error["loc"][-1] - raise UnsupportedConstraintError( - f"Constraint {key} is not supported for type {model!r}." - ) from e + except RuntimeError as e: + if "Unable to apply constraint" in str(e): + raise UnsupportedConstraintError(str(e)) from e raise e diff --git a/tests/test_properties.py b/tests/test_properties.py index f7182440..2d4fd9e9 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -438,7 +438,7 @@ def test_bad_property_constraints(): """Test that bad constraints raise errors at definition time.""" class BadConstraintThing(lt.Thing): - bad_prop: int = lt.property(default=0, allow_inf_nan=False) + bad_prop: str = lt.property(default="hello", allow_inf_nan=True) # Some constraints cause errors when the model is built. So far # I believe only allow_inf_nan on int does this.