diff options
author | manav014 <dpsman13016@gmail.com> | 2020-12-30 07:52:17 +0530 |
---|---|---|
committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-12-30 13:11:47 +0100 |
commit | a9a7421ab83361746549d574ca13438ba93c95fe (patch) | |
tree | b37af83e6ffa3c9efba803d1bad5a717c32a310b /tests/invalid_models_tests | |
parent | 74fd233b1433da8c68de636172ee1c9c6d1c08c9 (diff) | |
download | django-a9a7421ab83361746549d574ca13438ba93c95fe.tar.gz |
Fixed #32294 -- Prevented ManyToManyField's hidden related name collisions between apps.
Diffstat (limited to 'tests/invalid_models_tests')
-rw-r--r-- | tests/invalid_models_tests/test_relative_fields.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/tests/invalid_models_tests/test_relative_fields.py b/tests/invalid_models_tests/test_relative_fields.py index 82b1b426cf..8909b12214 100644 --- a/tests/invalid_models_tests/test_relative_fields.py +++ b/tests/invalid_models_tests/test_relative_fields.py @@ -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): |