diff --git a/django/contrib/auth/checks.py b/django/contrib/auth/checks.py index e7b5815..9f02304 100644 --- a/django/contrib/auth/checks.py +++ b/django/contrib/auth/checks.py @@ -111,7 +111,10 @@ def check_models_permissions(app_configs=None, **kwargs): opts = model._meta builtin_permissions = dict(_get_builtin_permissions(opts)) # Check builtin permission name length. - max_builtin_permission_name_length = max(len(name) for name in builtin_permissions.values()) + if builtin_permissions: + max_builtin_permission_name_length = max(len(name) for name in builtin_permissions.values()) + else: + max_builtin_permission_name_length = 0 if max_builtin_permission_name_length > permission_name_max_length: verbose_name_max_length = ( permission_name_max_length - (max_builtin_permission_name_length - len(opts.verbose_name_raw)) diff --git a/tests/auth_tests/test_checks.py b/tests/auth_tests/test_checks.py index 962444f..9855870 100644 --- a/tests/auth_tests/test_checks.py +++ b/tests/auth_tests/test_checks.py @@ -195,3 +195,12 @@ class ModelsPermissionsChecksTests(SimpleTestCase): id='auth.E008', ), ]) + + def test_empty_permission_name_max_length(self): + """should not fail on empty permissions""" + class Checked(models.Model): + class Meta: + permissions = () + default_permissions = () + errors = checks.run_checks(self.apps.get_app_configs()) + self.assertEqual(errors, [])