-
-
Couldn't load subscription status.
- Fork 54
fix: implement __lt__ for models still missing it
#899
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
fix: implement __lt__ for models still missing it
#899
Conversation
Since cyclonedx-python-lib has the tendency to use SortedSets to store deserialized instances, this can lead to errors like these: TypeError: '<' not supported between instances of 'ComponentEvidence' and 'ComponentEvidence' When loading a CycloneDX JSON SBOM using Bom.from_json(). This is due to the lack of 'less-than' operator, which is now implemented with __lt__ for all models that were still missing it. We implemented it this way since that's how it's done for all the existing models, but an easier implementation would propably to add functools' @total_ordering decorator to those classes. Signed-off-by: Quentin Kaiser <quentin.kaiser@onekey.com>
a84710c to
548d66e
Compare
|
thanks for your work. Could you elaborate why the implementation of
|
which JSON did you use? Anyway, is there a place where |
__lt__ for models still missing it__lt__ for models still missing it
I figured I might as well do it everywhere it was missing, regardless of whether it was already triggering a bug. |
I'll send a reduced test case, just a moment. |
|
@jkowalleck you can run the repro-899.py script to trigger the exception when parsing bom-899.json from cyclonedx.model.bom import Bom
import json
from pathlib import Path
Bom.from_json(json.loads(Path("bom-899.json").read_text()))This is what you should see: The SBOM was generated by https://github.com/CycloneDX/cdxgen, and the comparison seems to be triggered by the fact that two components with the same name and version but difference occurrences is present in the SBOM ( |
|
tested deserializing the bom-899.json did not see error message you posted. instead, i see the reason for the shown error will be solved with #900 anyway, i still see no prove why any of the changes in this PR are needed. |
#900 was merged, and this branch was updated. Understood. thanks for the report and the fix. |
__lt__ for models still missing it__lt__ for models still missing it
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
|
Yay ! Thanks for being so quick with this @jkowalleck, highly appreciated. |
Since cyclonedx-python-lib has the tendency to use SortedSets to store deserialized instances, this can lead to errors like these:
When loading a CycloneDX JSON SBOM using
Bom.from_json().This is due to the lack of 'less-than' operator, which is now implemented with
__lt__for all models that were still missing it.We implemented it this way since that's how it's done for all the existing models, but an easier implementation would propably to add functools'
@total_orderingdecorator to all classes.