tefra/xsdata

`Error: Cross reference detected` for unused complex types

hoehrmann opened this issue · 4 comments

Tried xsdata with https://github.com/sdmx-twg/sdmx-ml/blob/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXMessage.xsd and got Error: Cross reference detected until I commented out the unused complex types it complains about.

Thanks for reporting @hoehrmann, I just tried it with the latest main and seems to be working just fine,

There is an issue with this month's release v24.3 and v24.3.1.

❯ git st On branch main Your branch is up to date with 'origin/main'.

Untracked files:
(use "git add ..." to include in what will be committed)
foo.py
generated/

nothing added to commit but untracked files present (use "git add" to track)
❯ xsdata https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXMessage.xsd
========= xsdata v24.3.1 / Python 3.11.8 / Platform linux =========

Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXMessage.xsd
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXMessageFooter.xsd
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXCommon.xsd
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/xml.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/xml.xsd
Builder: 4 main and 1 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXCommonReferences.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXCommonReferences.xsd
Builder: 168 main and 0 inner classes
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXCommon.xsd
Builder: 76 main and 0 inner classes
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXMessageFooter.xsd
Builder: 4 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructure.xsd
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureBase.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureBase.xsd
Builder: 23 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureCategorisation.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureCategorisation.xsd
Builder: 2 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureCategory.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureCategory.xsd
Builder: 3 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureCodelist.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureCodelist.xsd
Builder: 23 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureConcept.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureConcept.xsd
Builder: 6 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureConstraint.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureConstraint.xsd
Builder: 34 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureDataStructure.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureDataStructure.xsd
Builder: 43 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureDataflow.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureDataflow.xsd
Builder: 1 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureHierarchicalCodelist.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureHierarchicalCodelist.xsd
Builder: 10 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureMetadataflow.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureMetadataflow.xsd
Builder: 2 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureMetadataStructure.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureMetadataStructure.xsd
Builder: 10 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureOrganisation.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureOrganisation.xsd
Builder: 21 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureProvisionAgreement.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureProvisionAgreement.xsd
Builder: 4 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureProcess.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureProcess.xsd
Builder: 8 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureReportingTaxonomy.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureReportingTaxonomy.xsd
Builder: 4 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureStructureMappings.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureStructureMappings.xsd
Builder: 24 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureTransformation.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructureTransformation.xsd
Builder: 36 main and 0 inner classes
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXStructure.xsd
Builder: 38 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXRegistry.xsd
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXRegistryBase.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXRegistryBase.xsd
Builder: 12 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXRegistryRegistration.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXRegistryRegistration.xsd
Builder: 9 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXRegistryStructure.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXRegistryStructure.xsd
Builder: 4 main and 0 inner classes
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXRegistrySubscription.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXRegistrySubscription.xsd
Builder: 19 main and 0 inner classes
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXRegistry.xsd
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXDataStructureSpecific.xsd
Parsing schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXMetadataGeneric.xsd
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXMetadataGeneric.xsd
Builder: 4 main and 0 inner classes
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXDataStructureSpecific.xsd
Builder: 7 main and 0 inner classes
Compiling schema https://raw.githubusercontent.com/sdmx-twg/sdmx-ml/29f1a3d856c4259429f5ec0eae811653adc5cdb5/schemas/SDMXMessage.xsd
Builder: 24 main and 0 inner classes
Analyzer input: 623 main and 1 inner classes
Analyzer output: 406 main and 0 inner classes
Generating package: init
Generating package: generated.sdmxcommon_references
Generating package: generated.sdmxcommon
Generating package: generated.sdmxmessage_footer
Generating package: generated.sdmxstructure_base
Generating package: generated.sdmxstructure_categorisation
Generating package: generated.sdmxstructure_category
Generating package: generated.sdmxstructure_codelist
Generating package: generated.sdmxstructure_concept
Generating package: generated.sdmxstructure_constraint
Generating package: generated.sdmxstructure_data_structure
Generating package: generated.sdmxstructure_dataflow
Generating package: generated.sdmxstructure_hierarchical_codelist
Generating package: generated.sdmxstructure_metadataflow
Generating package: generated.sdmxstructure_metadata_structure
Generating package: generated.sdmxstructure_organisation
Generating package: generated.sdmxstructure_provision_agreement
Generating package: generated.sdmxstructure_process
Generating package: generated.sdmxstructure_reporting_taxonomy
Generating package: generated.sdmxstructure_structure_mappings
Generating package: generated.sdmxstructure_transformation
Generating package: generated.sdmxstructure
Generating package: generated.sdmxregistry_base
Generating package: generated.sdmxregistry_registration
Generating package: generated.sdmxregistry_structure
Generating package: generated.sdmxregistry_subscription
Generating package: generated.sdmxmetadata_generic
Generating package: generated.sdmxdata_structure_specific
Generating package: generated.sdmxmessage

Okay, and thanks for the quick reaction!

FWIW:

The schema might be an interesting test case for xsdata, the generated code cannot be loaded due to circular imports, and some of the code looks a bit weird (though as a first time user I have no reference for what to expect). I suspect the schema is a bit unusual because they also derive a JSON Schema from it. The pattern that causes the circular import is a base type that is a union of foo: list-of-foo, bar: list-of-bar, ... and then there are Foo and Bar that derive from the base and restrict it to their corresponding list (so the base type needs the derived types, and the derived types need the base, hence a circular reference). The properties could be erased from the base, they never really exist there. This might also be causing some Anys that seem odd to me.

At the moment xsdata doesn't know if the generated code has circular imports, but it comes with different structure styles that can resolve this issue.

I took the liberty to add the suite in the samples repo, I used clusters and that took care of the circular import issues, there were a few issues that were resolved here

You can check it here, with some notes about some further limitations with mypy

https://github.com/tefra/xsdata-samples/tree/main/sdmx_ml, check the .xsdata.xml config I used

Give it a try @hoehrmann and if you find anything else, feel free to open another issue