Skip to content

Commit

Permalink
Changed the way we create class names for deferred field models to avoid
Browse files Browse the repository at this point in the history
problems when people have hundreds of fields on model. Maximum class
name length is now 80 characters and uses a hash when necessary.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13819 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
malcolmt committed Sep 13, 2010
1 parent 4084bc7 commit 17a79d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions django/db/backends/util.py
Expand Up @@ -105,15 +105,15 @@ def rev_typecast_decimal(d):
return None return None
return str(d) return str(d)


def truncate_name(name, length=None): def truncate_name(name, length=None, hash_len=4):
"""Shortens a string to a repeatable mangled version with the given length. """Shortens a string to a repeatable mangled version with the given length.
""" """
if length is None or len(name) <= length: if length is None or len(name) <= length:
return name return name


hash = md5_constructor(name).hexdigest()[:4] hash = md5_constructor(name).hexdigest()[:hash_len]


return '%s%s' % (name[:length-4], hash) return '%s%s' % (name[:length-hash_len], hash)


def format_number(value, max_digits, decimal_places): def format_number(value, max_digits, decimal_places):
""" """
Expand Down
6 changes: 4 additions & 2 deletions django/db/models/query_utils.py
Expand Up @@ -9,6 +9,7 @@
import weakref import weakref
from django.utils.copycompat import deepcopy from django.utils.copycompat import deepcopy


from django.db.backends import util
from django.utils import tree from django.utils import tree
from django.utils.datastructures import SortedDict from django.utils.datastructures import SortedDict


Expand Down Expand Up @@ -262,9 +263,10 @@ class Meta:


# The app_cache wants a unique name for each model, otherwise the new class # The app_cache wants a unique name for each model, otherwise the new class
# won't be created (we get an old one back). Therefore, we generate the # won't be created (we get an old one back). Therefore, we generate the
# name using the passed in attrs. It's OK to reuse an old case if the attrs # name using the passed in attrs. It's OK to reuse an existing class
# are identical. # object if the attrs are identical.
name = "%s_Deferred_%s" % (model.__name__, '_'.join(sorted(list(attrs)))) name = "%s_Deferred_%s" % (model.__name__, '_'.join(sorted(list(attrs))))
name = util.truncate_name(name, 80, 32)


overrides = dict([(attr, DeferredAttribute(attr, model)) overrides = dict([(attr, DeferredAttribute(attr, model))
for attr in attrs]) for attr in attrs])
Expand Down

0 comments on commit 17a79d5

Please sign in to comment.