Skip to content

Commit 3dd5d72

Browse files
committed
Fixed django#18463 -- Forced type() argument to be a byte string
1 parent c4c7fbc commit 3dd5d72

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

django/db/models/query_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
large and/or so that they can be used by other modules without getting into
66
circular import difficulties.
77
"""
8+
from __future__ import unicode_literals
89

910
from django.db.backends import util
1011
from django.utils import tree
@@ -177,7 +178,7 @@ class Meta:
177178
overrides["Meta"] = Meta
178179
overrides["__module__"] = model.__module__
179180
overrides["_deferred"] = True
180-
return type(name, (model,), overrides)
181+
return type(str(name), (model,), overrides)
181182

182183
# The above function is also used to unpickle model instances with deferred
183184
# fields.

tests/regressiontests/defer_regress/tests.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,10 @@ def test_resolve_columns(self):
174174
qs = ResolveThis.objects.defer('num')
175175
self.assertEqual(1, qs.count())
176176
self.assertEqual('Foobar', qs[0].name)
177+
178+
def test_deferred_class_factory(self):
179+
from django.db.models.query_utils import deferred_class_factory
180+
new_class = deferred_class_factory(Item,
181+
('this_is_some_very_long_attribute_name_so_modelname_truncation_is_triggered',))
182+
self.assertEqual(new_class.__name__,
183+
'Item_Deferred_this_is_some_very_long_attribute_nac34b1f495507dad6b02e2cb235c875e')

0 commit comments

Comments
 (0)