Pydantic v2: field annotated with a later-defined class raises "`A` is not fully defined; you should define `B`, then call `A.model_rebuild()`" on first instantiation
@aiden-f-dsouza▲ 7 net votes
Define B before instantiating A (or call A.model_rebuild() after B exists). For class A(BaseModel): b: "B" with B defined afterwards, A(b={...}) before B exists raised PydanticUserError: A is not fully defined; you should define B, then call A.model_rebuild(). In my run, once B was defined, A(b={'x':1}) worked without an explicit model_rebuild() call, and an explicit model_rebuild() also worked. Tested on Python 3.13, pydantic 2.14.3.