-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
pydantic_core._pydantic_core.SchemaError: Definitions error: definition XYZ
was never filled
#8984
Comments
Maybe I'm being dumb, but I don't think your code is valid python. |
Why do you think that? Python 3.12 will execute the code if I use a |
https://docs.python.org/3/library/typing.html#type-aliases - |
I believe this is a bug in our handling of nested type aliases. Definitely intend to fix it, not sure how complicated it will be.. |
I'm also seeing this, even without the use of a type alias. Inheriting from a generic class produces the same explosion. Something like: from pydantic import BaseModel
from typing import Generic, TypeVar
_T = TypeVar("_T", MyType0, MyType1)
@dataclass
class Inner(Generic[_T]):
field0: _T
field1: _T
@dataclass
class InnerMyType0(Inner[MyType0]):
pass
class Outer(BaseModel):
inner: InnerMyType0 throws something like
The reason I need this alias is that my OpenAPI schema generator incorrectly renders the generic (even when the type arguments are substituted) as polymorphic, and the added class was hoped to work around the problem. |
I'm running into this issue as well -- does anyone have a workaround? |
Here is another example: from collections.abc import Sequence
from pydantic import TypeAdapter
type JSON = str | int | bool | JSONSeq | JSONObj | None
type JSONObj = dict[str, JSON]
type JSONSeq = list[JSON]
type MyJSONAlias = JSON
# MyJSONAlias = JSON
type JSONs = Sequence[MyJSONAlias]
adapter = TypeAdapter(JSONs) causes
If I replace |
Here is another example, which does not involve generics (tested with pydantic v2.8.2 and Python 3.12.2): from dataclasses import dataclass
import pydantic
type Vars = list[str]
type Expr = str
type Fun = tuple[Vars, Expr]
type IntPred = Fun
@dataclass
class ConjectureExpr:
property: IntPred
# Error: pydantic_core._pydantic_core.SchemaError: Definitions error:
# definition `__main__.Fun:4380830240` was never filled
pydantic.TypeAdapter(ConjectureExpr) |
Initial Checks
Description
It seems that a generic type alias that is later "filled" via a second type alias confuses Pydantic. If you use
my_int_seq: MySeq[int]
then this error doesn't occur, it's only when the second alias exists that this causes an error.Full stack trace:
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: