Skip to content

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

Closed

Description

@0t1s1

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

Activity

  1. jkowalleck commented on Jan 29, 2022

    @jkowalleck
    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.
  2. madpah commented on Jan 31, 2022

    @madpah
    Collaborator

    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.

  3. madpah commented on Jan 31, 2022

    @madpah
    Collaborator

    Thanks for the report @0t1s1 !

  4. self-assigned this
    on Jan 31, 2022
  5. added
    bug
    on Jan 31, 2022
  6. modified the milestone: 1.4.0 on Jan 31, 2022
  7. added this to the 1.4.0 milestone on Feb 2, 2022
  8. linked a pull request that will close this issueRELEASE 2.0.0 #148on Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions