Skip to content

Commit

Permalink
Ensued that SQL indexes are alwasy created in the same name.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Alex Gaynor committed Sep 7, 2012
1 parent a92b81b commit e4ea536
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion django/db/backends/creation.py
Original file line number Original file line Diff line number Diff line change
@@ -1,3 +1,4 @@
import hashlib
import sys import sys
import time import time


Expand Down Expand Up @@ -27,7 +28,10 @@ def _digest(self, *args):
Generates a 32-bit digest of a set of arguments that can be used to Generates a 32-bit digest of a set of arguments that can be used to
shorten identifying names. 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()): def sql_create_model(self, model, style, known_models=set()):
""" """
Expand Down

0 comments on commit e4ea536

Please sign in to comment.