From 3dd5d726d1c3bf8f5901c992d7586e5ec146bc2d Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Mon, 11 Jun 2012 22:05:13 +0200 Subject: [PATCH] Fixed #18463 -- Forced type() argument to be a byte string --- django/db/models/query_utils.py | 3 ++- tests/regressiontests/defer_regress/tests.py | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/django/db/models/query_utils.py b/django/db/models/query_utils.py index 5676fdce9a..a7c176fd8f 100644 --- a/django/db/models/query_utils.py +++ b/django/db/models/query_utils.py @@ -5,6 +5,7 @@ Factored out from django.db.models.query to avoid making the main module very large and/or so that they can be used by other modules without getting into circular import difficulties. """ +from __future__ import unicode_literals from django.db.backends import util from django.utils import tree @@ -177,7 +178,7 @@ def deferred_class_factory(model, attrs): overrides["Meta"] = Meta overrides["__module__"] = model.__module__ overrides["_deferred"] = True - return type(name, (model,), overrides) + return type(str(name), (model,), overrides) # The above function is also used to unpickle model instances with deferred # fields. diff --git a/tests/regressiontests/defer_regress/tests.py b/tests/regressiontests/defer_regress/tests.py index c9baad6a1f..1f07d4c9a8 100644 --- a/tests/regressiontests/defer_regress/tests.py +++ b/tests/regressiontests/defer_regress/tests.py @@ -174,3 +174,10 @@ class DeferRegressionTest(TestCase): qs = ResolveThis.objects.defer('num') self.assertEqual(1, qs.count()) self.assertEqual('Foobar', qs[0].name) + + def test_deferred_class_factory(self): + from django.db.models.query_utils import deferred_class_factory + new_class = deferred_class_factory(Item, + ('this_is_some_very_long_attribute_name_so_modelname_truncation_is_triggered',)) + self.assertEqual(new_class.__name__, + 'Item_Deferred_this_is_some_very_long_attribute_nac34b1f495507dad6b02e2cb235c875e')