Skip to content

Commit c9888dd

Browse files
authored
Merge pull request #234 from DenSinH/dev
omit pydantic(-xml) fields when checking for model field validators
2 parents 6310ee2 + 8ff159a commit c9888dd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pydantic_xml/model.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,12 @@ def __init_subclass__(
429429

430430
cls.__xml_field_serializers__ = {}
431431
cls.__xml_field_validators__ = {}
432-
for attr_name in dir(cls):
432+
433+
# find custom validators/serializers in all defined attributes
434+
# though we want to skip any Base(Xml)Model attributes, as these can never be field
435+
# serializers/validators, and getting certain pydantic fields, like __pydantic_post_init__
436+
# may cause recursion errors for recursive / self-referential models
437+
for attr_name in set(dir(cls)) - set(dir(BaseXmlModel)):
433438
if func := getattr(cls, attr_name, None):
434439
if fields := getattr(func, '__xml_field_serializer__', None):
435440
for field in fields:

0 commit comments

Comments
 (0)