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

Nondeterministic string hashing in Python(>3.3) #52

Open
Cjen1 opened this issue Mar 6, 2023 · 1 comment
Open

Nondeterministic string hashing in Python(>3.3) #52

Cjen1 opened this issue Mar 6, 2023 · 1 comment

Comments

@Cjen1
Copy link

Cjen1 commented Mar 6, 2023

I was running into some weird issues with incorrect caching to file a function applied to a string.

This is because python(>3.3) salts its hashing function. (for strings at least)
Specifically:

> python -c "print(hash('asdf'))"
-8690208562067163084
> python -c "print(hash('asdf'))"
-4220296486527231708

The fix for this is to pass in PYTHONHASHSEED=1.
The 'proper' fix would be to substitute the internal hash function for something more suitable, however I couldn't immediately see the right place to inject that.

PYTHONHASHSEED=1 python -c "print(hash('asdf'))"
-5132432945605986887
PYTHONHASHSEED=1 python -c "print(hash('asdf'))"
-5132432945605986887

@tillahoffmann
Copy link
Collaborator

Thanks for reporting. This should only be a problem if results are cached across different processes. Do you have a reproducible code snippet to illustrate the issue?

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

No branches or pull requests

2 participants