-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Stealth breaking change 2.9 -> 2.10 for type sequences #11853
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
Comments
An extra check was introduced in 2.10 by #10621. In 2.11, you get a proper error:
The code you were using in 2.9 was somewhat unsafe. First, you probably expected Anyway, instead of using class Endpoint(BaseModel):
endpoint_func: Callable
input_schema: INPUT_SCHEMA
output_schema: OUTPUT_SCHEMA
@field_validator("output_schema", mode="plain")
@classmethod
def validate_output_schema(cls, v: OUTPUT_SCHEMA) -> OUTPUT_SCHEMA:
... Currently, your validator is an after validator. What happens is that Pydantic first validates against the type hint. Because |
Thanks for the quick reply! I applied your suggestions - removed With 2.11.4 I get the error you mentioned: However, applying the suggestion from error message -> changing Is there a way around it? Thanks for pointing out |
|
Initial Checks
Description
I wrote a code envisioned to be a generic interface to Data Science libraries, where the basic unit of input output is a DATA_MODEL -> BaseModel, Sequence of BaseModels or Pandera DataFrame model (last one irrelevant for this example).
Library can have 1+ endpoints, where each endpoint is a callable that has arguments that are DATA_MODELs (some of them optional) and output that is a single DATA_MODEL, or tuple of them.
It required some custom validators, but the whole setup shown below worked well in 2.9. Starting from 2.10, Endpoint Class definition throws an error:
TypeError: Expected a class, got typing.Sequence[pydantic.main.BaseModel]
already at the Endpoint model definition.
From my understanding of the error, the
Type[Sequence[BaseModel]]
trips it.Is this intended behaviour, how can I work around that error or improve my code to not trigger it?
Thank you for all the great work!
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: