Built-in hash() method is not deterministic, which breaks cachier since #17
See original GitHub issueCachier is broken for me since #17 for string arguments (probably for other built-in objects as well).
This comes from the fact that the built-in hash() method is not deterministic between runs in python.
Therefore calling it on the arguments of the function for caching purpose does not work between multiple runs because it will hash to different values.
The problematic call to hash() is here.
Repro
Run this script twice in a row and it will re-execute the method test() each time without relying on the cache:
import time
from cachier import cachier
@cachier(pickle_reload=False)
def test(text):
time.sleep(1)
print(text)
print(hash(text))
return 0
start_time = time.time()
text = 'foo'
print(hash(text))
test(text)
print(time.time() - start_time)
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:7
Top Results From Across the Web
Why isn't the hash function deterministic? - Stack Overflow
The default hash is the object's memory address and in no way related to those three properties. Implement __hash__ if you want a...
Read more >Deterministic hashing of Python data objects - death and gravity
An easy solution seems to be the built-in hash() function, which returns the integer hash of an object. However, it has a couple...
Read more >7. Cryptographic Hashes - Computer Security - CS 161
The hash function, H H , is deterministic, meaning if you compute H(M) H ( M ) twice with the same input M...
Read more >Why is string.GetHashCode() different each time I run my ...
In this post I discuss string.GetHashCode(), why it's randomised, and hash-attacks. I also provide a deterministic implementation you can ...
Read more >Build a Hash Table in Python With TDD
Python comes with a built-in hashlib module, which provides a variety of ... It may seem like hash() is a non-deterministic function, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks for fixing this so quickly!
Should be solved by release v1.3.3. Please check and let me know how it goes; you should definitely reopen this issue if this doesn’t fix the issue.