Skip to content

Fix several issues with the hashing method#2110

Merged
giovannipizzi merged 11 commits into
aiidateam:developfrom
dev-zero:fix_python3_hashing
Oct 25, 2018
Merged

Fix several issues with the hashing method#2110
giovannipizzi merged 11 commits into
aiidateam:developfrom
dev-zero:fix_python3_hashing

Conversation

@dev-zero
Copy link
Copy Markdown
Contributor

@dev-zero dev-zero commented Oct 24, 2018

This is an an alternative to #2049 using Blake2b as the hash algorithm (in tree configuration).

Besides fixing the same issues, I discovered some other problems which slipped through the cracks:

  • the dispatch on int type works differently between Python 2 and 3: while a np.int64 was matched by it in Python 2, Python 3 was using the string type instead, which is why we are using numbers.Integral now
  • we can't distinguish in hash types between str, bytes and unicode. Otherwise a simple "..." will be a differerent hash type in Python 2 and 3
  • furthermore I also made everything byte-ordner agnostic by converting numerical types to little-endian if necessary
  • for some of the representations I used struct.pack with the little-endian standard for getting the byte representation instead of the string representation. Arbitrary length of integers are therefore currently not supported I guess.

I guess it may make sense to squash @greschd 's commits with my main commit. So, instead of reviewing the diff, it is probably better to review the final code.

@coveralls

This comment has been minimized.

1 similar comment
@coveralls

This comment has been minimized.

@coveralls
Copy link
Copy Markdown

coveralls commented Oct 24, 2018

Coverage Status

Coverage decreased (-3.8%) to 64.821% when pulling c417c1a on dev-zero:fix_python3_hashing into 0b016a0 on aiidateam:develop.

@dev-zero dev-zero force-pushed the fix_python3_hashing branch 2 times, most recently from 75a3407 to b6d0d09 Compare October 25, 2018 08:05
Comment thread aiida/common/hashing.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing hash of the filename

Comment thread aiida/common/hashing.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One needs a end of sequence (same for sets, dicts)

Comment thread aiida/common/hashing.py Outdated
Comment thread aiida/common/hashing.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Todo: Ensure this function consistently returns unicode

Comment thread aiida/common/test_hashing.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: for make_hash, when an OrderedDict is passed, check for a kwarg (e.g. 'consider_as_unsorted' or a better name): if True, continue; if False, raise

@dev-zero
Copy link
Copy Markdown
Contributor Author

@giovannipizzi do you want to talk another look at the changes dec77be ?

giovannipizzi
giovannipizzi previously approved these changes Oct 25, 2018
@dev-zero
Copy link
Copy Markdown
Contributor Author

@giovannipizzi I rebased, can you do a squash&merge please?

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.

4 participants