From 8aaf51f94c70e3cfcd2c75a0be1b6f55049d82d8 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Thu, 11 Dec 2014 12:36:13 -0700 Subject: [PATCH] Revert "Fixed #23455 -- Forced related_name to be a unicode string during deconstruction." This reverts commit 45bd7b3bd9008941580c100b9fc7361e3ff3ff0d. --- django/db/models/fields/related.py | 6 +++--- docs/releases/1.7.2.txt | 4 ++++ tests/field_deconstruction/tests.py | 12 ------------ 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index a3e4a1d9eba..8a6d87c5ac5 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -14,7 +14,7 @@ from django.db.models.lookups import IsNull from django.db.models.related import RelatedObject, PathInfo from django.db.models.query import QuerySet from django.db.models.expressions import Col -from django.utils.encoding import force_text, smart_text +from django.utils.encoding import smart_text from django.utils import six from django.utils.translation import ugettext_lazy as _ from django.utils.functional import curry, cached_property @@ -1441,7 +1441,7 @@ class ForeignObject(RelatedField): kwargs['from_fields'] = self.from_fields kwargs['to_fields'] = self.to_fields if self.rel.related_name is not None: - kwargs['related_name'] = force_text(self.rel.related_name) + kwargs['related_name'] = self.rel.related_name if self.rel.related_query_name is not None: kwargs['related_query_name'] = self.rel.related_query_name if self.rel.on_delete != CASCADE: @@ -2244,7 +2244,7 @@ class ManyToManyField(RelatedField): if self.rel.db_constraint is not True: kwargs['db_constraint'] = self.rel.db_constraint if self.rel.related_name is not None: - kwargs['related_name'] = force_text(self.rel.related_name) + kwargs['related_name'] = self.rel.related_name if self.rel.related_query_name is not None: kwargs['related_query_name'] = self.rel.related_query_name # Rel needs more work. diff --git a/docs/releases/1.7.2.txt b/docs/releases/1.7.2.txt index df66a505b47..0f1483e18e4 100644 --- a/docs/releases/1.7.2.txt +++ b/docs/releases/1.7.2.txt @@ -124,3 +124,7 @@ Bugfixes * Fixed a crash in the admin when using "Save as new" and also deleting a related inline (:ticket:`23857`). + +* Removed auto-conversion of ``related_name`` to unicode in field + deconstruction, to maintain consistency of bytes/text in migrations matching + the original values (:ticket:`23455` and :ticket:`23982`). diff --git a/tests/field_deconstruction/tests.py b/tests/field_deconstruction/tests.py index 998d1ab9809..4c1aabb94b5 100644 --- a/tests/field_deconstruction/tests.py +++ b/tests/field_deconstruction/tests.py @@ -211,12 +211,6 @@ class FieldDeconstructionTests(TestCase): self.assertEqual(path, "django.db.models.ForeignKey") self.assertEqual(args, []) self.assertEqual(kwargs, {"to": "auth.Permission", "related_name": "foobar"}) - # Test related_name unicode conversion - field = models.ForeignKey("auth.Permission", related_name=b"foobar") - name, path, args, kwargs = field.deconstruct() - self.assertEqual(path, "django.db.models.ForeignKey") - self.assertEqual(args, []) - self.assertEqual(kwargs, {"to": "auth.Permission", "related_name": "foobar"}) @override_settings(AUTH_USER_MODEL="auth.Permission") def test_foreign_key_swapped(self): @@ -297,12 +291,6 @@ class FieldDeconstructionTests(TestCase): self.assertEqual(path, "django.db.models.ManyToManyField") self.assertEqual(args, []) self.assertEqual(kwargs, {"to": "auth.Permission", "related_name": "custom_table"}) - # Test related_name unicode conversion - field = models.ManyToManyField("auth.Permission", related_name=b"custom_table") - name, path, args, kwargs = field.deconstruct() - self.assertEqual(path, "django.db.models.ManyToManyField") - self.assertEqual(args, []) - self.assertEqual(kwargs, {"to": "auth.Permission", "related_name": "custom_table"}) @override_settings(AUTH_USER_MODEL="auth.Permission") def test_many_to_many_field_swapped(self):