mirror of
https://github.com/django/django.git
synced 2025-03-09 17:02:43 +00:00
Fixed #12288 -- Validated that app names in INSTALLED_APPS are unique
This commit is contained in:
parent
ad6fcdb8d2
commit
c1ec08998d
@ -109,8 +109,9 @@ class BaseSettings(object):
|
|||||||
"to a tuple, not a string.")
|
"to a tuple, not a string.")
|
||||||
elif name == "INSTALLED_APPS":
|
elif name == "INSTALLED_APPS":
|
||||||
value = list(value) # force evaluation of generators on Python 3
|
value = list(value) # force evaluation of generators on Python 3
|
||||||
if len(value) != len(set(value)):
|
apps = [s.split('.')[-1] for s in value]
|
||||||
raise ImproperlyConfigured("The INSTALLED_APPS setting must contain unique values.")
|
if len(value) != len(set(apps)):
|
||||||
|
raise ImproperlyConfigured("The INSTALLED_APPS setting must contain unique app names.")
|
||||||
|
|
||||||
object.__setattr__(self, name, value)
|
object.__setattr__(self, name, value)
|
||||||
|
|
||||||
|
@ -241,11 +241,14 @@ class UniqueSettingsTests(TestCase):
|
|||||||
def test_unique(self):
|
def test_unique(self):
|
||||||
"""
|
"""
|
||||||
An ImproperlyConfigured exception is raised if the INSTALLED_APPS contains
|
An ImproperlyConfigured exception is raised if the INSTALLED_APPS contains
|
||||||
any duplicate strings.
|
any duplicate appication names.
|
||||||
"""
|
"""
|
||||||
with self.assertRaises(ImproperlyConfigured):
|
with self.assertRaises(ImproperlyConfigured):
|
||||||
self.settings_module.INSTALLED_APPS = ("myApp1", "myApp1", "myApp2", "myApp3")
|
self.settings_module.INSTALLED_APPS = ("myApp1", "myApp1", "myApp2", "myApp3")
|
||||||
|
|
||||||
|
with self.assertRaises(ImproperlyConfigured):
|
||||||
|
self.settings_module.INSTALLED_APPS = ("package1.myApp1", "package2.myApp1")
|
||||||
|
|
||||||
|
|
||||||
class TrailingSlashURLTests(TestCase):
|
class TrailingSlashURLTests(TestCase):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user