66from weakref import WeakSet
77from pydantic import BaseModel , ConfigDict , Field , RootModel , create_model
88from pydantic .dataclasses import dataclass
9- from pydantic_core import SchemaError
109
1110from labthings_fastapi .exceptions import UnsupportedConstraintError
1211from .introspection import EmptyObject
@@ -129,7 +128,7 @@ def wrap_plain_types_in_rootmodel(
129128 :raises UnsupportedConstraintError: if constraints are provided for an
130129 unsuitable type, for example `allow_inf_nan` for an `int` property, or
131130 any constraints for a `BaseModel` subclass.
132- :raises SchemaError : if other errors prevent Pydantic from creating a schema
131+ :raises RuntimeError : if other errors prevent Pydantic from creating a schema
133132 for the generated model.
134133 """
135134 try : # This needs to be a `try` as basic types are not classes
@@ -148,13 +147,9 @@ def wrap_plain_types_in_rootmodel(
148147 root = (model , Field (** constraints )),
149148 __base__ = LabThingsRootModelWrapper ,
150149 )
151- except SchemaError as e :
152- for error in e .errors ():
153- if error ["loc" ][- 1 ] in constraints :
154- key = error ["loc" ][- 1 ]
155- raise UnsupportedConstraintError (
156- f"Constraint { key } is not supported for type { model !r} ."
157- ) from e
150+ except RuntimeError as e :
151+ if "Unable to apply constraint" in str (e ):
152+ raise UnsupportedConstraintError (str (e )) from e
158153 raise e
159154
160155
0 commit comments