Skip to content

Add xs:id and xs:idref resolution - #1222

Open
pahjbo wants to merge 19 commits into
tefra:mainfrom
pahjbo:idref
Open

Add xs:id and xs:idref resolution#1222
pahjbo wants to merge 19 commits into
tefra:mainfrom
pahjbo:idref

Conversation

@pahjbo

@pahjbo pahjbo commented Jun 26, 2026

Copy link
Copy Markdown

📒 Description

This pull request adds support for XML IDREF fields in dataclass models, and adds functionality that is similar to Java's JAXB handling of @XmlID and @XmlIDREF annotations in that when serialising an attribute that is marked as an IDREF, then only ID is emitted, and then when parsing such an XML instance the ID is replaced with the full dataclass instance.

This is related to the discussion item #1221

🔗 What I've Done

I have added two extra metadata items

  • at the field level - idref as bool that signifies if the attribute is an xs:IDREF
  • at the class Meta level - key as a list[str] that lists the attribute names that when the values are concatenated make up the xs:ID

This second one might seem a little complex, but I have a use case where I need such a thing, and hopefully the unit test example makes this plausible.

Once the data model has been set up, the render and parse are transparent to the caller with the conversion to an xs:ID and the instantiation of the appropriate object happening automatically

💬 Comments

I know that this is an unsolicited new feature, that you might not want to spend time on, but I believe that it is valuable to people with complex XML structures.

There are probably more tests that you might want, but I would need a bit more help with using your harness to do them.
Also If you like the idea, then I can spend some more time on documentation.

🛫 Checklist

  • Updated docs
  • Added unit-tests - only an "end to end" test - perhaps some of the individual components e.g. IdRefNode could have some tests
  • Sample tests pass
  • W3C tests pass

pahjbo added 12 commits June 25, 2026 12:13
the key attribute is a list of strings that are the attribute names that when concatenated make up the XMLID for the class
This is only a step on the way as it is
doing IDREF sweeps at the end of the parse - it would more efficient to do the resolution during the parse.
in order to test multiple unresolved idrefs
to check that is still working after list was supported.

also sort the imports
avoids clash with another test class
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.97%. Comparing base (1fda878) to head (6eb2267).

Additional details and impacted files
@@           Coverage Diff            @@
##             main    #1222    +/-   ##
========================================
  Coverage   99.97%   99.97%            
========================================
  Files         116      117     +1     
  Lines        9393     9495   +102     
  Branches     1444     1467    +23     
========================================
+ Hits         9391     9493   +102     
  Misses          1        1            
  Partials        1        1            

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

pahjbo added a commit to ivoa/vo-dml that referenced this pull request Jul 15, 2026
… not using the pydantic json functions, but the ones in vodml_runtime.xsdata

* will only work with modified xsdata - see tefra/xsdata#1222
* will only work for the "wrapped" VO-DML polymorphism style.
* there is still probably some cruft to remove from the vodml_runtime.xsdata classes, as the starting point was the general equivalent classes from xsdata itself
pahjbo added a commit to ivoa/vo-dml that referenced this pull request Jul 15, 2026
…on-serialization

Add pydantic-xml model generation, XML/JSON schema validation tests, and CI workflow

now probably at a "beta" stage - it requires a modified xsdata (see see tefra/xsdata#1222) to work
@sonarqubecloud

Copy link
Copy Markdown

@pahjbo

pahjbo commented Jul 22, 2026

Copy link
Copy Markdown
Author

@tefra could you please give this a review?

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.

1 participant