summaryrefslogtreecommitdiff
path: root/django/db/models
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2011-08-25 06:07:28 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2011-08-25 06:07:28 +0000
commit587fbff3dd500cd3444dc7a0717e541307ff869d (patch)
tree2c487d69c84e17d618647365b1de44c40a4a9d56 /django/db/models
parent20473057d13ac3e774ae29a1557ce4d18e7cdce6 (diff)
Make ManyToManyField model references more robust.
In r16679 a test was added to verify something had been fixed when a unicode string type was passed in as a model name. The name has to be ASCII convertible, but in Python 2.6 and earlier, it must also have str type. This commit fixes the problem for earlier Python versions and is almost identical to a patch from b.leskes in #6045. Fixes #16689. Refs #6045. git-svn-id: http://code.djangoproject.com/svn/django/trunk@16682 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/db/models')
-rw-r--r--django/db/models/fields/related.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index 3e861cddd2..d904f56cd6 100644
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -1007,6 +1007,10 @@ class ManyToManyField(RelatedField, Field):
assert not to._meta.abstract, "%s cannot define a relation with abstract class %s" % (self.__class__.__name__, to._meta.object_name)
except AttributeError: # to._meta doesn't exist, so it must be RECURSIVE_RELATIONSHIP_CONSTANT
assert isinstance(to, basestring), "%s(%r) is invalid. First parameter to ManyToManyField must be either a model, a model name, or the string %r" % (self.__class__.__name__, to, RECURSIVE_RELATIONSHIP_CONSTANT)
+ # Python 2.6 and earlier require dictionary keys to be of str type,
+ # not unicode and class names must be ASCII (in Python 2.x), so we
+ # forcibly coerce it here (breaks early if there's a problem).
+ to = str(to)
kwargs['verbose_name'] = kwargs.get('verbose_name', None)
kwargs['rel'] = ManyToManyRel(to,