Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

omit pydantic(-xml) fields when checking for model field validators #234

Merged
merged 1 commit into from
Nov 28, 2024
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
7 changes: 6 additions & 1 deletion pydantic_xml/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,12 @@ def __init_subclass__(

cls.__xml_field_serializers__ = {}
cls.__xml_field_validators__ = {}
for attr_name in dir(cls):

# find custom validators/serializers in all defined attributes
# though we want to skip any Base(Xml)Model attributes, as these can never be field
# serializers/validators, and getting certain pydantic fields, like __pydantic_post_init__
# may cause recursion errors for recursive / self-referential models
for attr_name in set(dir(cls)) - set(dir(BaseXmlModel)):
if func := getattr(cls, attr_name, None):
if fields := getattr(func, '__xml_field_serializer__', None):
for field in fields:
Expand Down
Loading