You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is an issue when merging fields in the _common_field_schema function in pydantic/_internal/_generate_schema.py. The issue is that field_info._attributes_set includes both FieldInfo attributes in addition to metadata so when the function checks if if k not in field_info._attributes_set (where k is a key from _attributes_set) and then uses setattr(field_info, k, v), it will fail for anything that isn't actually an attribute of the object (i.e. anything that is in the metadata). Sorry if this is a poor explanation, I have a test which fails below.
This bug was introduced in #7698. cc @dmontagu I see you authored the original PR. I wish I could put up a fix myself but I don't fully understand the purpose of the code.
@jsmith Thanks for reporting. I believe I have fixed the issue in #8494. (I stole your test, thanks very much for that.)
It would be great if you could confirm whether that fixes your issues; it at least made the test you provided pass (with some additional validation that it behaves correctly when the metadata should not be overwritten).
Initial Checks
Description
There is an issue when merging fields in the
_common_field_schema
function inpydantic/_internal/_generate_schema.py
. The issue is thatfield_info._attributes_set
includes bothFieldInfo
attributes in addition to metadata so when the function checks ifif k not in field_info._attributes_set
(where k is a key from_attributes_set
) and then usessetattr(field_info, k, v)
, it will fail for anything that isn't actually an attribute of the object (i.e. anything that is in the metadata). Sorry if this is a poor explanation, I have a test which fails below.This bug was introduced in #7698. cc @dmontagu I see you authored the original PR. I wish I could put up a fix myself but I don't fully understand the purpose of the code.
Here is my branch with a test that reproduces the bug:
main...jsmith:pydantic:jsmith/fix-generate-schema-annotation-merge
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: