Skip to content

Commit

Permalink
Resolve group and attrGroup name collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
tefra committed Sep 5, 2022
1 parent 4938f32 commit 698d0df
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
hooks:
- id: reorder-python-imports
- repo: https://github.com/ambv/black
rev: 22.6.0
rev: 22.8.0
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
Expand Down
4 changes: 2 additions & 2 deletions tests/codegen/handlers/test_flatten_attribute_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_process(self, mock_process_attribute, mock_is_group):
@mock.patch.object(ClassUtils, "copy_group_attributes")
def test_process_attribute_with_group(self, mock_copy_group_attributes):
complex_bar = ClassFactory.create(qname="bar", tag=Tag.COMPLEX_TYPE)
group_bar = ClassFactory.create(qname="bar", tag=Tag.GROUP)
group_bar = ClassFactory.create(qname="bar", tag=Tag.ATTRIBUTE_GROUP)
group_attr = AttrFactory.attribute_group(name="bar")
target = ClassFactory.create()
target.attrs.append(group_attr)
Expand Down Expand Up @@ -80,7 +80,7 @@ def test_process_attribute_with_attribute_group(self, mock_copy_group_attributes

def test_process_attribute_with_circular_reference(self):
group_attr = AttrFactory.attribute_group(name="bar")
target = ClassFactory.create(qname="bar", tag=Tag.GROUP)
target = ClassFactory.create(qname="bar", tag=Tag.ATTRIBUTE_GROUP)
target.attrs.append(group_attr)

target.status = Status.FLATTENING
Expand Down
5 changes: 2 additions & 3 deletions xsdata/codegen/handlers/flatten_attribute_groups.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from xsdata.codegen.mixins import RelativeHandlerInterface
from xsdata.codegen.models import Attr
from xsdata.codegen.models import Class
from xsdata.codegen.models import is_group
from xsdata.codegen.utils import ClassUtils
from xsdata.exceptions import AnalyzerValueError


class FlattenAttributeGroups(RelativeHandlerInterface):
"""Replace attribute groups with the source class attributes."""
"""Replace groupS and attGroups with the source class attributes."""

__slots__ = ()

Expand Down Expand Up @@ -36,7 +35,7 @@ def process_attribute(self, target: Class, attr: Attr):
:raises AnalyzerValueError: if source class is not found.
"""
qname = attr.types[0].qname # group attributes have one type only.
source = self.container.find(qname, condition=is_group)
source = self.container.find(qname, condition=lambda x: x.tag == attr.tag)

if not source:
raise AnalyzerValueError(f"Group attribute not found: `{qname}`")
Expand Down

0 comments on commit 698d0df

Please sign in to comment.