diff --git a/.changeset/pydantic-cycle-fix.md b/.changeset/pydantic-cycle-fix.md new file mode 100644 index 000000000..f18c53749 --- /dev/null +++ b/.changeset/pydantic-cycle-fix.md @@ -0,0 +1,7 @@ +--- +default: patch +--- + +# Fix for rare Pydantic error + +Fixed a subtle issue with forward type references in Pydantic classes that could, in very rare cases, cause the parser to fail with the error "`Parameter` is not fully defined". diff --git a/openapi_python_client/schema/openapi_schema_pydantic/header.py b/openapi_python_client/schema/openapi_schema_pydantic/header.py index 3223c199b..2d2471ea9 100644 --- a/openapi_python_client/schema/openapi_schema_pydantic/header.py +++ b/openapi_python_client/schema/openapi_schema_pydantic/header.py @@ -29,3 +29,10 @@ class Header(Parameter): ] }, ) + + +# Calling model_rebuild() here helps Pydantic to resolve the forward references that were used +# in defining Parameter and Encoding. Without this call, any subtle change to the loading order +# of schema submodules could result in an error like "Parameter is not fully defined". +# See: https://docs.pydantic.dev/latest/concepts/models/#rebuilding-model-schema +Parameter.model_rebuild()