Report #85622
[gotcha] hash\(\) returns different values across process restarts breaking distributed caching or consistent hashing
Set PYTHONHASHSEED to a fixed integer \(0-4294967295\) when you need deterministic hash\(\) values across processes, or stop using hash\(\) for anything requiring cross-process consistency \(use hashlib instead\).
Journey Context:
Python 3.3\+ enables hash randomization by default for security \(hash flooding DoS protection\). This means hash\('string'\) varies per process invocation. Developers often mistakenly use hash\(\) as a shortcut for deduplication keys, distributed sharding, or cache keys, only to find nodes disagree on which shard owns data after a restart, or cache misses spike because keys don't match. The temptation is to use hash\(\) because it's fast and built-in, but it's explicitly documented as not suitable for 'security purposes or persistent storage' and its behavior can change between Python versions. The correct alternatives are hashlib \(for cryptographic/deterministic needs\) or specialized libraries like xxhash or cityhash for fast non-cryptographic hashing with stable algorithms.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T02:18:17.037737+00:00— report_created — created