Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1733 from joaoxsouls/#18866

Fixed #18866 -- added validation error for verbose_name longer than 39 characters
  • Loading branch information...
commit 8ce3c3a9282ac19282060ddf6928b34a09d26672 2 parents 8fc6308 + 1ab27e9
Marc Tamlyn mjtamlyn authored
1  AUTHORS
View
@@ -463,6 +463,7 @@ answer newbie questions, and generally made Django that much better:
Neal Norwitz <nnorwitz@google.com>
Todd O'Bryan <toddobryan@mac.com>
Alex Ogier <alex.ogier@gmail.com>
+ Joao Oliveira <joaoxsouls@gmail.com>
Selwin Ong <selwin@ui.co.id>
Gerardo Orozco <gerardo.orozco.mosqueda@gmail.com>
Christian Oudard <christian.oudard@gmail.com>
6 django/contrib/auth/management/__init__.py
View
@@ -99,6 +99,12 @@ def create_permissions(app, created_models, verbosity, db=DEFAULT_DB_ALIAS, **kw
for ctype, (codename, name) in searched_perms
if (ctype.pk, codename) not in all_perms
]
+ # Validate the permissions before bulk_creation to avoid cryptic
+ # database error when the verbose_name is longer than 50 characters
+ for perm in perms:
+ if len(perm.name) > 50:
+ raise exceptions.ValidationError(
+ "The verbose_name of %s is longer than 39 characters" % perm.content_type)
auth_app.Permission.objects.using(db).bulk_create(perms)
if verbosity >= 2:
for perm in perms:
12 django/contrib/auth/tests/test_management.py
View
@@ -8,6 +8,7 @@
from django.contrib.auth.tests.custom_user import CustomUser
from django.contrib.auth.tests.utils import skipIfCustomUser
from django.contrib.contenttypes.models import ContentType
+from django.core import exceptions
from django.core.management import call_command
from django.core.management.base import CommandError
from django.core.management.validation import get_validation_errors
@@ -201,10 +202,12 @@ class PermissionTestCase(TestCase):
def setUp(self):
self._original_permissions = models.Permission._meta.permissions[:]
self._original_default_permissions = models.Permission._meta.default_permissions
+ self._original_verbose_name = models.Permission._meta.verbose_name
def tearDown(self):
models.Permission._meta.permissions = self._original_permissions
models.Permission._meta.default_permissions = self._original_default_permissions
+ models.Permission._meta.verbose_name = self._original_verbose_name
ContentType.objects.clear_cache()
def test_duplicated_permissions(self):
@@ -258,3 +261,12 @@ def test_default_permissions(self):
self.assertEqual(models.Permission.objects.filter(
content_type=permission_content_type,
).count(), 1)
+
+ def test_verbose_name_length(self):
+ permission_content_type = ContentType.objects.get_by_natural_key('auth', 'permission')
+ models.Permission.objects.filter(content_type=permission_content_type).delete()
+ models.Permission._meta.verbose_name = "some ridiculously long verbose name that is out of control"
+
+ six.assertRaisesRegex(self, exceptions.ValidationError,
+ "The verbose_name of permission is longer than 39 characters",
+ create_permissions, models, [], verbosity=0)
Please sign in to comment.
Something went wrong with that request. Please try again.