mirror of https://github.com/django/django.git
Fixed #32285 -- Raised ImproperlyConfigured when AppConfig.label is not a valid Python identifier.
This commit is contained in:
parent
110001d0bb
commit
8b2a30f6f1
|
@ -34,6 +34,10 @@ class AppConfig:
|
||||||
# This value must be unique across a Django project.
|
# This value must be unique across a Django project.
|
||||||
if not hasattr(self, 'label'):
|
if not hasattr(self, 'label'):
|
||||||
self.label = app_name.rpartition(".")[2]
|
self.label = app_name.rpartition(".")[2]
|
||||||
|
if not self.label.isidentifier():
|
||||||
|
raise ImproperlyConfigured(
|
||||||
|
"The app label '%s' is not a valid Python identifier." % self.label
|
||||||
|
)
|
||||||
|
|
||||||
# Human-readable name for the application e.g. "Admin".
|
# Human-readable name for the application e.g. "Admin".
|
||||||
if not hasattr(self, 'verbose_name'):
|
if not hasattr(self, 'verbose_name'):
|
||||||
|
|
|
@ -436,6 +436,14 @@ class AppConfigTests(SimpleTestCase):
|
||||||
ac = AppConfig('label', Stub(__path__=['a']))
|
ac = AppConfig('label', Stub(__path__=['a']))
|
||||||
self.assertEqual(repr(ac), '<AppConfig: label>')
|
self.assertEqual(repr(ac), '<AppConfig: label>')
|
||||||
|
|
||||||
|
def test_invalid_label(self):
|
||||||
|
class MyAppConfig(AppConfig):
|
||||||
|
label = 'invalid.label'
|
||||||
|
|
||||||
|
msg = "The app label 'invalid.label' is not a valid Python identifier."
|
||||||
|
with self.assertRaisesMessage(ImproperlyConfigured, msg):
|
||||||
|
MyAppConfig('test_app', Stub())
|
||||||
|
|
||||||
@override_settings(
|
@override_settings(
|
||||||
INSTALLED_APPS=['apps.apps.ModelPKAppsConfig'],
|
INSTALLED_APPS=['apps.apps.ModelPKAppsConfig'],
|
||||||
DEFAULT_AUTO_FIELD='django.db.models.SmallAutoField',
|
DEFAULT_AUTO_FIELD='django.db.models.SmallAutoField',
|
||||||
|
|
Loading…
Reference in New Issue