Skip to content

Fix Advisory.__hash__() - #189

Merged
haikoschol merged 1 commit into
aboutcode-org:developfrom
haikoschol:fix_advisory_hash
Jun 4, 2020
Merged

Fix Advisory.__hash__()#189
haikoschol merged 1 commit into
aboutcode-org:developfrom
haikoschol:fix_advisory_hash

Conversation

@haikoschol

Copy link
Copy Markdown
Collaborator

The hash is computed from a string, which is built by iterating over attributes of type Iterable/Sequence, such as impacted_package_urls.

This change sorts those attributes before concatenating to the string, to avoid different hashes when the order of impacted_package_urls, etc differs.

NB A better solution would be to avoid implementing __hash__() and use immutable collections like tuple and frozenset for the above mentioned attributes instead.

See https://eng.lyft.com/hashing-and-equality-in-python-2ea8c738fb9d

The hash is computed from a string, which is built by iterating over
attributes of type Iterable/Sequence, such as impacted_package_urls.

This change sorts those attributes before concatenating to the string,
to avoid different hashes when the order of impacted_package_urls, etc
differs.

NB A better solution would be to avoid implementing __hash__() and use
immutable collections like tuple and frozenset for the above mentioned
attributes instead.

See https://eng.lyft.com/hashing-and-equality-in-python-2ea8c738fb9d

Signed-off-by: Haiko Schol <hs@haikoschol.com>
@haikoschol
haikoschol requested a review from sbs2001 June 4, 2020 14:41
@sbs2001

sbs2001 commented Jun 4, 2020

Copy link
Copy Markdown
Collaborator

Works fine, tried running those tests 100 times, passed each time, feel free to merge.

@haikoschol
haikoschol merged commit de1b8e7 into aboutcode-org:develop Jun 4, 2020
@haikoschol
haikoschol deleted the fix_advisory_hash branch April 10, 2023 00:43
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

Successfully merging this pull request may close these issues.

2 participants