Skip to content

Commit

Permalink
fix: Avoid conflict with attributes named value when flattening exten…
Browse files Browse the repository at this point in the history
…sions (#1085)

* fix: Avoid conflict with attributes named value when flattening extensions

* chore: Update pre-commit hooks
  • Loading branch information
tefra authored Nov 3, 2024
1 parent dd587cd commit 827210b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ repos:
- id: end-of-file-fixer
- id: debug-statements
- repo: https://github.com/crate-ci/typos
rev: v1.26.0
rev: v1.27.0
hooks:
- id: typos
exclude: ^tests/|.xsd|xsdata/models/datatype.py$
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.0
rev: v0.7.2
hooks:
- id: ruff
args: [ --fix, --show-fixes]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.12.1
rev: v1.13.0
hooks:
- id: mypy
files: ^(xsdata/)
Expand Down
10 changes: 10 additions & 0 deletions tests/codegen/handlers/test_flatten_class_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,13 @@ def test_add_default_attribute_with_any_type(self):
self.assertEqual(0, len(item.extensions))
self.assertEqual(expected, item.attrs[0])
self.assertEqual(expected.restrictions, item.attrs[0].restrictions)

def test_get_or_create_attribute_ignore_existing_attribute(self):
target = ClassFactory.create()
attr = AttrFactory.create(tag=Tag.ATTRIBUTE, name="value")

result = FlattenClassExtensions.get_or_create_attribute(
target, "value", Tag.EXTENSION
)

self.assertIsNot(attr.tag, result)
2 changes: 1 addition & 1 deletion xsdata/codegen/handlers/flatten_class_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ def get_or_create_attribute(cls, target: Class, name: str, tag: str) -> Attr:
tag: The attr tag name
"""
attr = ClassUtils.find_attr(target, name)
if attr is None:
if attr is None or attr.tag == Tag.ATTRIBUTE:
attr = Attr(name=name, tag=tag)
attr.restrictions.min_occurs = 1
attr.restrictions.max_occurs = 1
Expand Down

0 comments on commit 827210b

Please sign in to comment.