Skip to content

Accept xs:anyAttribute wildcards - #80

Merged
martinv13 merged 1 commit into
cre-dev:mainfrom
fabbiot:fix-any-attribute
Oct 14, 2026
Merged

martinv13 merged 1 commit into
cre-dev:mainfrom
fabbiot:fix-any-attribute

Conversation

@fabbiot

@fabbiot fabbiot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

A type with an xs:anyAttribute wildcard makes DataModel fail while building the model:

  File "src/xml2db/model.py", line 438, in _parse_tree
    ) = recurse_parse_simple_type([attrib.type])
  File "src/xml2db/model.py", line 363, in recurse_parse_simple_type
    if elem_type.is_union():
AttributeError: 'NoneType' object has no attribute 'is_union'

xmlschema lists the wildcard in the type's attributes under the key None, with no type, and the attribute loop in _parse_tree passes it to recurse_parse_simple_type. This change skips it with a warning, as #52 does for xs:any children: the schema is accepted and the wildcard content is not imported. No model config can avoid the error today, since it is raised before the config is applied.

Found with SDMX 2.1 structure-specific data, for instance the ECB exchange rates schema (https://data-api.ecb.europa.eu/service/schema/dataflow/ECB/EXR/1.0). The SDMX base types DataSetType, GroupType, SeriesType and ObsType declare <xs:anyAttribute namespace="##local"/> so that each data structure can add its own attributes by restriction. The wildcard cannot be removed from the schema: xmlschema then rejects the restrictions (Unexpected attribute 'CURRENCY' in restriction).

Tests

Extra in orders.xsd gets an xs:anyAttribute, and equivalent_xml/order1a.xml sets an attribute on <extra>. Without the change in model.py, 85 tests fail with the error above. With it, the suite passes on DuckDB (TZ="Europe/Paris" DB_STRING="duckdb:///:memory:" pytest: 229 passed, 73 skipped). Regenerating the snapshots with models.py changes nothing, since the wildcard adds no column.

Docs

A "Wildcards" caveat in docs/how_it_works.md. mkdocs build --strict passes.

🤖 Generated with Claude Code

A type with an xs:anyAttribute made DataModel fail with
"'NoneType' object has no attribute 'is_union'": xmlschema lists the
wildcard in the type's attributes under the key None, without a type.
Skip it with a warning, as done for xs:any children in cre-dev#52.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@martinv13
martinv13 merged commit 25af1df into cre-dev:main Oct 14, 2026
9 of 10 checks passed
@martinv13

Copy link
Copy Markdown
Collaborator

Thanks, that is useful!
A minor, unrelated failure with python 3.10 build, which we should retire anyways as it is now EOL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants