Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Changed the way we create class names for deferred field models to avoid

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...
commit 17a79d503302f3aad5e2439d858d6e3cbba102e4 1 parent 4084bc7
Malcolm Tredinnick authored September 13, 2010
6  django/db/backends/util.py
@@ -105,15 +105,15 @@ def rev_typecast_decimal(d):
105 105
         return None
106 106
     return str(d)
107 107
 
108  
-def truncate_name(name, length=None):
  108
+def truncate_name(name, length=None, hash_len=4):
109 109
     """Shortens a string to a repeatable mangled version with the given length.
110 110
     """
111 111
     if length is None or len(name) <= length:
112 112
         return name
113 113
 
114  
-    hash = md5_constructor(name).hexdigest()[:4]
  114
+    hash = md5_constructor(name).hexdigest()[:hash_len]
115 115
 
116  
-    return '%s%s' % (name[:length-4], hash)
  116
+    return '%s%s' % (name[:length-hash_len], hash)
117 117
 
118 118
 def format_number(value, max_digits, decimal_places):
119 119
     """
6  django/db/models/query_utils.py
@@ -9,6 +9,7 @@
9 9
 import weakref
10 10
 from django.utils.copycompat import deepcopy
11 11
 
  12
+from django.db.backends import util
12 13
 from django.utils import tree
13 14
 from django.utils.datastructures import SortedDict
14 15
 
@@ -262,9 +263,10 @@ class Meta:
262 263
 
263 264
     # The app_cache wants a unique name for each model, otherwise the new class
264 265
     # won't be created (we get an old one back). Therefore, we generate the
265  
-    # name using the passed in attrs. It's OK to reuse an old case if the attrs
266  
-    # are identical.
  266
+    # name using the passed in attrs. It's OK to reuse an existing class
  267
+    # object if the attrs are identical.
267 268
     name = "%s_Deferred_%s" % (model.__name__, '_'.join(sorted(list(attrs))))
  269
+    name = util.truncate_name(name, 80, 32)
268 270
 
269 271
     overrides = dict([(attr, DeferredAttribute(attr, model))
270 272
             for attr in attrs])

0 notes on commit 17a79d5

Please sign in to comment.
Something went wrong with that request. Please try again.