#19178: create_permissions method fails if the model has a single new permission
------------------------------+--------------------
     Reporter:  mariocesar    |      Owner:  nobody
         Type:  Bug           |     Status:  new
    Component:  contrib.auth  |    Version:  1.4
     Severity:  Normal        |   Keywords:
 Triage Stage:  Unreviewed    |  Has patch:  0
Easy pickings:  0             |      UI/UX:  0
------------------------------+--------------------
 I notice this by using this command → https://gist.github.com/3946353, it
 list all apps and update the permissions in the db if there is any new.

 The stacktrace is:

 {{{
 Traceback (most recent call last):
   File "/home/mariocesar/Proyectos/Crowddeals/env/local/lib/python2.7
 /site-packages/django/core/management/base.py", line 222, in run_from_argv
     self.execute(*args, **options.__dict__)
   File "/home/mariocesar/Proyectos/Crowddeals/env/local/lib/python2.7
 /site-packages/django/core/management/base.py", line 252, in execute
     output = self.handle(*args, **options)
   File
 
"/home/mariocesar/Proyectos/Crowddeals/crowddeals/core/management/commands/update_permissions.py",
 line 29, in handle
     create_permissions(app, get_models(), options.get('verbosity', 0))
   File "/home/mariocesar/Proyectos/Crowddeals/env/local/lib/python2.7
 /site-packages/django/contrib/auth/management/__init__.py", line 74, in
 create_permissions
     for perm in _get_all_permissions(klass._meta, ctype):
   File "/home/mariocesar/Proyectos/Crowddeals/env/local/lib/python2.7
 /site-packages/django/contrib/auth/management/__init__.py", line 28, in
 _get_all_permissions
     _check_permission_clashing(custom, builtin, ctype)
   File "/home/mariocesar/Proyectos/Crowddeals/env/local/lib/python2.7
 /site-packages/django/contrib/auth/management/__init__.py", line 49, in
 _check_permission_clashing
     for codename, _name in custom:
 ValueError: too many values to unpack
 }}}


 I see that in ´contrib/auth/management/__init__.py´ the method
 _check_permission_clashing unpack the custom new methods. Normally the
 list of permissions will be a list of list, however if there is just one
 new permission, when getting the permissiosn it returns just a list of
 strings.

 Making the _get_all_permissios code aware of that will fix the problem.

 {{{
 def _get_all_permissions(opts, ctype):
     """
     Returns (codename, name) for all permissions in the given opts.
     """
     builtin = _get_builtin_permissions(opts)
     custom = list(opts.permissions)
     _check_permission_clashing(custom, builtin, ctype)
     return builtin + custom
 }}}

 {{{
 def _get_all_permissions(opts, ctype):
     """
     Returns (codename, name) for all permissions in the given opts.
     """
     builtin = _get_builtin_permissions(opts)
     custom = list(opts.permissions)

     if any(isinstance(el, basestring) for el in custom):
         custom = [custom]

     _check_permission_clashing(custom, builtin, ctype)
     return builtin + custom
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19178>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to