Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML deserialization incorrectly reports missing text for tags with text #17

Closed
empwilli opened this issue Feb 8, 2024 · 1 comment
Closed

Comments

@empwilli
Copy link

empwilli commented Feb 8, 2024

Steps to reproduce

filename = "simple.xml"

try:
    environment = xmlization.environment_from_file(filename)
except xmlization.DeserializationException as deserialize_error:
    raise deserialize_error

Current behaviour (bug)

The XML deserialization wrongly attests that some valid XML files are invalid. This results in a failure to deserialize the asset administrative shell.

Expected behaviour (correct)

Successfully deserialize the shell.

Relevant logs and/or media (optional)

Traceback (most recent call last):
  ..
    environment = xmlization.environment_from_file(filename)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 7581, in environment_from_file
    return environment_from_iterparse(_with_elements_cleared_after_yield(iterator))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 7503, in environment_from_iterparse
    raise exception
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 7500, in environment_from_iterparse
    return _read_environment_as_element(next_element, iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 21046, in _read_environment_as_element
    return _read_environment_as_sequence(element, iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 21011, in _read_environment_as_sequence
    read_and_set_method(reader_and_setter, next_element, iterator)
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 20888, in read_and_set_submodels
    item = _read_submodel_as_element(next_element, iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 12063, in _read_submodel_as_element
    return _read_submodel_as_sequence(element, iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 12015, in _read_submodel_as_sequence
    read_and_set_method(reader_and_setter, next_element, iterator)
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 11941, in read_and_set_submodel_elements
    item = _read_submodel_element_as_element(next_element, iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 12091, in _read_submodel_element_as_element
    return read_as_sequence(element, iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 13090, in _read_submodel_element_list_as_sequence
    read_and_set_method(reader_and_setter, next_element, iterator)
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 13014, in read_and_set_value
    item = _read_submodel_element_as_element(next_element, iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 12091, in _read_submodel_element_as_element
    return read_as_sequence(element, iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 13593, in _read_submodel_element_collection_as_sequence
    read_and_set_method(reader_and_setter, next_element, iterator)
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 13517, in read_and_set_value
    item = _read_submodel_element_as_element(next_element, iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 12091, in _read_submodel_element_as_element
    return read_as_sequence(element, iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 13090, in _read_submodel_element_list_as_sequence
    read_and_set_method(reader_and_setter, next_element, iterator)
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 13014, in read_and_set_value
    item = _read_submodel_element_as_element(next_element, iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 12091, in _read_submodel_element_as_element
    return read_as_sequence(element, iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 13593, in _read_submodel_element_collection_as_sequence
    read_and_set_method(reader_and_setter, next_element, iterator)
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 13517, in read_and_set_value
    item = _read_submodel_element_as_element(next_element, iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 12091, in _read_submodel_element_as_element
    return read_as_sequence(element, iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 13593, in _read_submodel_element_collection_as_sequence
    read_and_set_method(reader_and_setter, next_element, iterator)
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 13517, in read_and_set_value
    item = _read_submodel_element_as_element(next_element, iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 12091, in _read_submodel_element_as_element
    return read_as_sequence(element, iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 14095, in _read_property_as_sequence
    read_and_set_method(reader_and_setter, next_element, iterator)
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 14011, in read_and_set_value_type
    self.value_type = _read_data_type_def_xsd_from_element_text(element, iterator)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 20462, in _read_data_type_def_xsd_from_element_text
    text = _read_text_from_element(element, iterator)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "..venv/lib/python3.11/site-packages/aas_core3/xmlization.py", line 9391, in _read_text_from_element
    raise DeserializationException(
aas_core3.xmlization.DeserializationException: Expected an element with text, but got an element with no text.

Minimal sample simple.zip

Other comment

The error is due to implementation details of the Python XML library (see the note for aas-core-works/aas-core-codegen#443 (comment)). It is thus dependend on the length of the XML file.

aas-core-works/aas-core-codegen#443 (comment) addresses this issue.

mristin added a commit that referenced this issue Feb 14, 2024
The ElementTree's `XMLPullParser` sometimes attaches the text to the
start element and sometimes to the end element. We could not figure out
why there is a different behavior, but suspect that it has something to
do with the size of the parser buffer.

In this patch, we fix by looking for text in both events (start as well
as end element).

This is related to the issue #17, and based on the aas-core-codegen
after the pull request
aas-core-works/aas-core-codegen#443 has been
merged in, [aas-core-codegen 330f391].

[aas-core-codegen 330f391]: aas-core-works/aas-core-codegen@330f391
mristin added a commit that referenced this issue Feb 14, 2024
The ElementTree's `XMLPullParser` sometimes attaches the text to the
start element and sometimes to the end element. We could not figure out
why there is a different behavior, but suspect that it has something to
do with the size of the parser buffer.

In this patch, we fix by looking for text in both events (start as well
as end element).

This is related to the issue #17, and based on the aas-core-codegen
after the pull request
aas-core-works/aas-core-codegen#443 has been
merged in, [aas-core-codegen 330f391].

[aas-core-codegen 330f391]: aas-core-works/aas-core-codegen@330f391
@mristin
Copy link
Contributor

mristin commented Feb 16, 2024

Fixed in #18.

@mristin mristin closed this as completed Feb 16, 2024
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

No branches or pull requests

2 participants