Skip to content

Commit

Permalink
unparametrized root models serializer generation bug fixed. Affected by
Browse files Browse the repository at this point in the history
  • Loading branch information
dapper91 committed Aug 17, 2023
1 parent 8ad6b6c commit ac04b34
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions examples/snippets/model_root_type.py
Expand Up @@ -10,8 +10,8 @@ class Socials(RootXmlModel, tag='socials'):
root: List[HttpUrl] = element(tag='social')


class Contacts(RootXmlModel[Socials], tag='contacts'):
pass
class Contacts(RootXmlModel, tag='contacts'):
root: Socials
# [model-end]


Expand Down
11 changes: 9 additions & 2 deletions pydantic_xml/model.py
Expand Up @@ -269,8 +269,15 @@ def __build_serializer__(cls) -> None:
if cls is BaseXmlModel:
return

if cls.__pydantic_generic_metadata__['parameters']: # checks that all generic parameters are provided
return
# checks that all generic parameters are provided
if cls.__pydantic_root_model__:
if cls.__pydantic_generic_metadata__['parameters'] and not cls.__annotations__.get('root'):
cls.__xml_serializer__ = None
return
else:
if cls.__pydantic_generic_metadata__['parameters']:
cls.__xml_serializer__ = None
return

if config.REGISTER_NS_PREFIXES and cls.__xml_nsmap__:
utils.register_nsmap(cls.__xml_nsmap__)
Expand Down

0 comments on commit ac04b34

Please sign in to comment.