Revert "Fixed #23455 -- Forced related_name to be a unicode string during deconstruction."
This reverts commit 45bd7b3bd9
.
This commit is contained in:
parent
df30ae07fc
commit
8aaf51f94c
|
@ -14,7 +14,7 @@ from django.db.models.lookups import IsNull
|
||||||
from django.db.models.related import RelatedObject, PathInfo
|
from django.db.models.related import RelatedObject, PathInfo
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
from django.db.models.expressions import Col
|
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 import six
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.utils.functional import curry, cached_property
|
from django.utils.functional import curry, cached_property
|
||||||
|
@ -1441,7 +1441,7 @@ class ForeignObject(RelatedField):
|
||||||
kwargs['from_fields'] = self.from_fields
|
kwargs['from_fields'] = self.from_fields
|
||||||
kwargs['to_fields'] = self.to_fields
|
kwargs['to_fields'] = self.to_fields
|
||||||
if self.rel.related_name is not None:
|
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:
|
if self.rel.related_query_name is not None:
|
||||||
kwargs['related_query_name'] = self.rel.related_query_name
|
kwargs['related_query_name'] = self.rel.related_query_name
|
||||||
if self.rel.on_delete != CASCADE:
|
if self.rel.on_delete != CASCADE:
|
||||||
|
@ -2244,7 +2244,7 @@ class ManyToManyField(RelatedField):
|
||||||
if self.rel.db_constraint is not True:
|
if self.rel.db_constraint is not True:
|
||||||
kwargs['db_constraint'] = self.rel.db_constraint
|
kwargs['db_constraint'] = self.rel.db_constraint
|
||||||
if self.rel.related_name is not None:
|
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:
|
if self.rel.related_query_name is not None:
|
||||||
kwargs['related_query_name'] = self.rel.related_query_name
|
kwargs['related_query_name'] = self.rel.related_query_name
|
||||||
# Rel needs more work.
|
# Rel needs more work.
|
||||||
|
|
|
@ -124,3 +124,7 @@ Bugfixes
|
||||||
|
|
||||||
* Fixed a crash in the admin when using "Save as new" and also deleting a
|
* Fixed a crash in the admin when using "Save as new" and also deleting a
|
||||||
related inline (:ticket:`23857`).
|
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`).
|
||||||
|
|
|
@ -211,12 +211,6 @@ class FieldDeconstructionTests(TestCase):
|
||||||
self.assertEqual(path, "django.db.models.ForeignKey")
|
self.assertEqual(path, "django.db.models.ForeignKey")
|
||||||
self.assertEqual(args, [])
|
self.assertEqual(args, [])
|
||||||
self.assertEqual(kwargs, {"to": "auth.Permission", "related_name": "foobar"})
|
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")
|
@override_settings(AUTH_USER_MODEL="auth.Permission")
|
||||||
def test_foreign_key_swapped(self):
|
def test_foreign_key_swapped(self):
|
||||||
|
@ -297,12 +291,6 @@ class FieldDeconstructionTests(TestCase):
|
||||||
self.assertEqual(path, "django.db.models.ManyToManyField")
|
self.assertEqual(path, "django.db.models.ManyToManyField")
|
||||||
self.assertEqual(args, [])
|
self.assertEqual(args, [])
|
||||||
self.assertEqual(kwargs, {"to": "auth.Permission", "related_name": "custom_table"})
|
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")
|
@override_settings(AUTH_USER_MODEL="auth.Permission")
|
||||||
def test_many_to_many_field_swapped(self):
|
def test_many_to_many_field_swapped(self):
|
||||||
|
|
Loading…
Reference in New Issue