diff options
| author | Alex Gaynor <alex.gaynor@rd.io> | 2012-09-07 14:14:06 -0400 |
|---|---|---|
| committer | Alex Gaynor <alex.gaynor@rd.io> | 2012-09-07 14:14:06 -0400 |
| commit | e4ea53677449cfc56a0093bfbd92cb482020bb1e (patch) | |
| tree | 063672a6318414efc1a0ced631d9212a9113c336 /django | |
| parent | a92b81b0e8adc47a1357a3fa26324cbda226f211 (diff) | |
Ensued that SQL indexes are alwasy created in the same name.
Previous this used Python's builtin hash() function, which has never been guarnteed to be stable across implementations (CPython/Jython/etc.) or 32/64 bitness. However, this in practice it was stable. However, with the impending release of Python 3.3 hash randomizations is enabled by default, which would mean the index name changed between program invocations.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/backends/creation.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py index 6ac55eb5ff..659d35ace3 100644 --- a/django/db/backends/creation.py +++ b/django/db/backends/creation.py @@ -1,3 +1,4 @@ +import hashlib import sys import time @@ -27,7 +28,10 @@ class BaseDatabaseCreation(object): Generates a 32-bit digest of a set of arguments that can be used to shorten identifying names. """ - return '%x' % (abs(hash(args)) % 4294967296) # 2**32 + h = hashlib.md5() + for arg in args: + h.update(arg) + return h.hexdigest()[:8] def sql_create_model(self, model, style, known_models=set()): """ |
