Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Avoided hardcoding Permission.name max_length

refs #18866.
  • Loading branch information...
commit 91c77eeab837ff793311ac5b0321015a4e66d6da 1 parent 3918eeb
@timgraham timgraham authored
Showing with 8 additions and 2 deletions.
  1. +8 −2 django/contrib/auth/management/__init__.py
View
10 django/contrib/auth/management/__init__.py
@@ -101,10 +101,16 @@ def create_permissions(app, created_models, verbosity, db=DEFAULT_DB_ALIAS, **kw
]
# Validate the permissions before bulk_creation to avoid cryptic
# database error when the verbose_name is longer than 50 characters
+ permission_name_max_length = auth_app.Permission._meta.get_field('name').max_length
+ verbose_name_max_length = permission_name_max_length - 11 # len('Can change ') prefix
for perm in perms:
- if len(perm.name) > 50:
+ if len(perm.name) > permission_name_max_length:
raise exceptions.ValidationError(
- "The verbose_name of %s is longer than 39 characters" % perm.content_type)
+ "The verbose_name of %s is longer than %s characters" % (
+ perm.content_type,
+ verbose_name_max_length,
+ )
+ )
auth_app.Permission.objects.using(db).bulk_create(perms)
if verbosity >= 2:
for perm in perms:
Please sign in to comment.
Something went wrong with that request. Please try again.