xsdata
xsdata copied to clipboard
Intermittent XMLSchemaKeyError with elements in sequence
Sometimes when parsing or serializing I get this error:
Processing: similar_types_choice_error.xml
--------------------------------------------------
Traceback (most recent call last):
File "/Users/pedro.almirall/work/xsdata-experiments/experiment/main.py", line 61, in <module>
main()
File "/Users/pedro.almirall/work/xsdata-experiments/experiment/main.py", line 43, in main
converter.validate_xml_string(reconstructed_xml_string)
File "/Users/pedro.almirall/work/xsdata-experiments/experiment/xml_converter.py", line 37, in validate_xml_string
self.schema.validate(xml_string)
File "/Users/pedro.almirall/work/xsdata-experiments/.venv/lib/python3.12/site-packages/xmlschema/validators/schemas.py", line 1335, in validate
for error in self.iter_errors(source, path, schema_path, use_defaults,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pedro.almirall/work/xsdata-experiments/.venv/lib/python3.12/site-packages/xmlschema/validators/schemas.py", line 1458, in iter_errors
xsd_element.raw_decode(elem, validation, context)
File "/Users/pedro.almirall/work/xsdata-experiments/.venv/lib/python3.12/site-packages/xmlschema/validators/elements.py", line 746, in raw_decode
content = content_decoder.raw_decode(obj, validation, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pedro.almirall/work/xsdata-experiments/.venv/lib/python3.12/site-packages/xmlschema/validators/groups.py", line 1036, in raw_decode
result_item = xsd_element.raw_decode(child, validation, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pedro.almirall/work/xsdata-experiments/.venv/lib/python3.12/site-packages/xmlschema/validators/elements.py", line 746, in raw_decode
content = content_decoder.raw_decode(obj, validation, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pedro.almirall/work/xsdata-experiments/.venv/lib/python3.12/site-packages/xmlschema/validators/groups.py", line 1005, in raw_decode
self.check_dynamic_context(child, xsd_element, model.element, namespaces)
File "/Users/pedro.almirall/work/xsdata-experiments/.venv/lib/python3.12/site-packages/xmlschema/validators/groups.py", line 878, in check_dynamic_context
xsd_type = self.maps.get_instance_type(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/pedro.almirall/work/xsdata-experiments/.venv/lib/python3.12/site-packages/xmlschema/validators/xsd_globals.py", line 241, in get_instance_type
xsi_type = self.types[extended_name]
~~~~~~~~~~^^^^^^^^^^^^^^^
File "/Users/pedro.almirall/work/xsdata-experiments/.venv/lib/python3.12/site-packages/xmlschema/validators/builders.py", line 394, in __getitem__
raise XMLSchemaKeyError(msg) from None
xmlschema.exceptions.XMLSchemaKeyError: "global component 'WorkAddress' not found"
Reproduction in this repo