summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Tamlyn <marc.tamlyn@gmail.com>2013-10-14 06:20:59 -0700
committerMarc Tamlyn <marc.tamlyn@gmail.com>2013-10-14 06:20:59 -0700
commit8ce3c3a9282ac19282060ddf6928b34a09d26672 (patch)
treeef194a9782881cb0a869eed8fbf9b3f2ada48d2e
parent8fc63087f6ad888b68dff17ee0c527774332d932 (diff)
parent1ab27e9a65015373a49688f3ff6723cf85d5de56 (diff)
Merge pull request #1733 from joaoxsouls/#18866
Fixed #18866 -- added validation error for verbose_name longer than 39 characters
-rw-r--r--AUTHORS1
-rw-r--r--django/contrib/auth/management/__init__.py6
-rw-r--r--django/contrib/auth/tests/test_management.py12
3 files changed, 19 insertions, 0 deletions
diff --git a/AUTHORS b/AUTHORS
index 0b270fec81..74f0aae2f0 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -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>
diff --git a/django/contrib/auth/management/__init__.py b/django/contrib/auth/management/__init__.py
index cb77694d1c..dafcda243a 100644
--- a/django/contrib/auth/management/__init__.py
+++ b/django/contrib/auth/management/__init__.py
@@ -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:
diff --git a/django/contrib/auth/tests/test_management.py b/django/contrib/auth/tests/test_management.py
index e56df0676b..edf433c835 100644
--- a/django/contrib/auth/tests/test_management.py
+++ b/django/contrib/auth/tests/test_management.py
@@ -8,6 +8,7 @@ from django.contrib.auth.models import User
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 @@ class PermissionTestCase(TestCase):
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)