Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nit: it looks like you could identify whether model rebuilding is necessary by inspecting the class's __pydantic_core_schema__. This could be used to conditionally calling Parameter.model_rebuild()

Copy link
Author

@eli-bl eli-bl Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess. I thought of that as a pydantic implementation detail, but I see that they did document it. However, I don't see a downside to just unconditionally calling model_rebuild, when we know for sure that there is a potential issue (due to the circular reference). This is a one-time action.