﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
19178	create_permissions method fails if the model has a single new permission	Mario César	nobody	"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
}}}"	Bug	closed	contrib.auth	1.4	Normal	wontfix		mhaligowski	Unreviewed	0	0	0	0	0	0
