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

__hash__ implementation in Component attempts to hash unhashable properties list if present #153

Closed
0t1s1 opened this issue Jan 28, 2022 · 3 comments · Fixed by #148
Closed
Assignees
Labels
bug Something isn't working
Milestone

Comments

@0t1s1
Copy link

0t1s1 commented Jan 28, 2022

The Component class' __hash__ implementation attempts to hash an unhashable list of Property objects if present. This prevents Component objects from being compared, which in turn prevents one from adding Component objects to Bom objects via Bom's add_component method.

Example:

from cyclonedx.model.component import Component
from cyclonedx.model import Property
component1 = Component("component 1", properties=[Property("prop 1", "value 1")])
component2 = Component("component 2")
component1 == component2

Results in

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/python3.8/site-packages/cyclonedx/model/component.py", line 508, in __eq__
    return hash(other) == hash(self)
  File "/lib/python3.8/site-packages/cyclonedx/model/component.py", line 512, in __hash__
    return hash((
TypeError: unhashable type: 'list'

Library version: 1.3.0
OS: CentOS 8

@jkowalleck
Copy link
Member

expected fix:

  1. implement unit tests that test the hash() on objects that are expected to hash.
  2. implement the __hash__() method in the classes that need one.

madpah added a commit that referenced this issue Jan 31, 2022
Signed-off-by: Paul Horton <phorton@sonatype.com>
@madpah
Copy link
Collaborator

madpah commented Jan 31, 2022

Agree @jkowalleck. This will require a fair bit of work to do "right", but will include a temp fix for this in the next release and leave this open to track a proper fix.

@madpah
Copy link
Collaborator

madpah commented Jan 31, 2022

Thanks for the report @0t1s1 !

@madpah madpah self-assigned this Jan 31, 2022
@madpah madpah added the bug Something isn't working label Jan 31, 2022
@madpah madpah modified the milestone: 1.4.0 Jan 31, 2022
@madpah madpah mentioned this issue Jan 31, 2022
madpah added a commit that referenced this issue Feb 1, 2022
…dded tests #153

Signed-off-by: Paul Horton <phorton@sonatype.com>
madpah added a commit that referenced this issue Feb 2, 2022
* fix: implemented correct `__hash__` methods in models (#153)

Signed-off-by: Paul Horton <phorton@sonatype.com>
@madpah madpah added this to the 1.4.0 milestone Feb 2, 2022
@madpah madpah linked a pull request Feb 2, 2022 that will close this issue
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.

3 participants