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

Empty Component Property cannot be deserialized #630

Closed
schlenk opened this issue Jun 10, 2024 · 3 comments · Fixed by #631
Closed

Empty Component Property cannot be deserialized #630

schlenk opened this issue Jun 10, 2024 · 3 comments · Fixed by #631
Labels
bug Something isn't working

Comments

@schlenk
Copy link
Contributor

schlenk commented Jun 10, 2024

A component with an empty property cannot be deserialized from XML.
At least cyclonedx-cli validate considers it as a valid.

This component cannot be deserialized:

<ns0:component type="library" bom-ref="example@15.8.0">
      <ns0:name>example</ns0:name>
      <ns0:version>15.8.0</ns0:version>
      <ns0:properties>
        <ns0:property name="cdx:npm:package:path" />
      </ns0:properties>
</ns0:component>

It fails with a traceback, as no value is found for the property:

  File ".venv\Lib\site-packages\serializable\__init__.py", line 603, in from_xml
    _data[decoded_k].append(prop_info.concrete_type.from_xml(
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv\Lib\site-packages\serializable\__init__.py", line 603, in from_xml
    _data[decoded_k].append(prop_info.concrete_type.from_xml(
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".venv\Lib\site-packages\serializable\__init__.py", line 656, in from_xml
    return cls(**_data)
           ^^^^^^^^^^^^
TypeError: Property.__init__() missing 1 required keyword-only argument: 'value'

Script and data to reproduce:
property_parse.zip

Versions used:

  • Python 3.11
  • cyclonedx-python-lib 7.4.0
  • py-serializable 1.0.3
@jkowalleck
Copy link
Member

solution: make the value of the property object optional, default None

@jkowalleck
Copy link
Member

@schlenk ,
thank you for the report and the reproducible example.
are you willing to provide/work on a fix?

@schlenk
Copy link
Contributor Author

schlenk commented Jun 11, 2024

I added a pull request for the code change, but have no idea how to properly add a test for it, as the test data setup is a bit confusing.

@jkowalleck jkowalleck added the bug Something isn't working label Jun 12, 2024
jkowalleck added a commit that referenced this issue Jun 12, 2024
`cyclonedx.model.Property.value` value is optional, in accordance with
the spec.

fixes #630

---------

Signed-off-by: Michael Schlenker <michael.schlenker@contact-software.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Co-authored-by: Michael Schlenker <michael.schlenker@contact-software.com>
Co-authored-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants