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

Resolve group and attrGroup name collisions #702

Merged
merged 1 commit into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
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
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