Skip to content

Commit

Permalink
Don't write invalid ref in <str:Categorisation>
Browse files Browse the repository at this point in the history
Follows fix for #180 in #218.
  • Loading branch information
khaeru committed Jan 14, 2025
1 parent 095056c commit 55f4e4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions sdmx/tests/writer/test_writer_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ def test_data_roundtrip(pytestconfig, specimen, data_id, structure_id, tmp_path)
@pytest.mark.parametrize(
"specimen_id, strict",
[
("BIS/gh-180.xml", False),
("ECB/orgscheme.xml", True),
("ECB_EXR/1/structure-full.xml", False),
("ESTAT/apro_mk_cola-structure.xml", True),
Expand Down
13 changes: 8 additions & 5 deletions sdmx/writer/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,14 @@ def _cl(obj: model.ComponentList, *args):

@writer
def _cat(obj: model.Categorisation):
return maintainable(
obj,
reference(obj.artefact, tag="str:Source", style="Ref"),
reference(obj.category, tag="str:Target", style="Ref"),
)
elem = maintainable(obj)
# If .reader.xml.v21._ref did not resolve a ref while reading (e.g. ref to a non-
# standard class like PublicationTable), this may be a dict → don't write. Generates
# XSD-invalid SDMX-ML; but occurs only when the input SDMX-ML was invalid anyway.
if isinstance(obj.artefact, common.IdentifiableArtefact):
elem.append(reference(obj.artefact, tag="str:Source", style="Ref"))
elem.append(reference(obj.category, tag="str:Target", style="Ref"))
return elem


# §10.3: Constraints
Expand Down

0 comments on commit 55f4e4f

Please sign in to comment.