1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Fixed #32294 -- Prevented ManyToManyField's hidden related name collisions between apps.

This commit is contained in:
manav014
2020-12-30 07:52:17 +05:30
committed by Mariusz Felisiak
parent 74fd233b14
commit a9a7421ab8
4 changed files with 44 additions and 14 deletions

View File

@@ -3,7 +3,7 @@ from unittest import mock
from django.core.checks import Error, Warning as DjangoWarning
from django.db import connection, models
from django.test.testcases import SimpleTestCase
from django.test.utils import isolate_apps, override_settings
from django.test.utils import isolate_apps, modify_settings, override_settings
@isolate_apps('invalid_models_tests')
@@ -1025,6 +1025,32 @@ class ReverseQueryNameClashTests(SimpleTestCase):
),
])
@modify_settings(INSTALLED_APPS={'append': 'basic'})
@isolate_apps('basic', 'invalid_models_tests')
def test_no_clash_across_apps_without_accessor(self):
class Target(models.Model):
class Meta:
app_label = 'invalid_models_tests'
class Model(models.Model):
m2m = models.ManyToManyField(Target, related_name='+')
class Meta:
app_label = 'basic'
def _test():
# Define model with the same name.
class Model(models.Model):
m2m = models.ManyToManyField(Target, related_name='+')
class Meta:
app_label = 'invalid_models_tests'
self.assertEqual(Model.check(), [])
_test()
self.assertEqual(Model.check(), [])
@isolate_apps('invalid_models_tests')
class ExplicitRelatedNameClashTests(SimpleTestCase):