views:

16

answers:

0

Hi everyone. I'm using Django 1.0, and I'm having a tricky problem with permissions and groups.

Having launched a site, I wanted to use more fine-grained permissions for the content editors, so that they can insert new content with django's built-in admin function, not having to worry about potential damage to those models they should not touch.

I went to the admin panel to edit user with ID 3, removed the superuser permissions, then tried to add single permissions; here's what happens:

  • The first permission I add always works
  • Removing all permissions always works
  • Adding a second permission, or more than one permission in one pass results in an IntegrityError.
  • The same happens when creating a group and assigning permissions to it.

Here's a traceback:

Traceback (most recent call last):

File "/var/lib/python-support/python2.5/django/core/handlers/base.py", line 86, in get_response response = callback(request, *callback_args, **callback_kwargs)

File "/var/lib/python-support/python2.5/django/contrib/admin/sites.py", line 157, in root return self.model_page(request, *url.split('/', 2))

File "/var/lib/python-support/python2.5/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)

File "/var/lib/python-support/python2.5/django/contrib/admin/sites.py", line 176, in model_page return admin_obj(request, rest_of_url)

File "/var/lib/python-support/python2.5/django/contrib/auth/admin.py", line 42, in call return super(UserAdmin, self).call(request, url)

File "/var/lib/python-support/python2.5/django/contrib/admin/options.py", line 197, in call return self.change_view(request, unquote(url))

File "/var/lib/python-support/python2.5/django/db/transaction.py", line 238, in _commit_on_success res = func(*args, **kw)

File "/var/lib/python-support/python2.5/django/contrib/admin/options.py", line 581, in change_view
form.save_m2m()

File "/var/lib/python-support/python2.5/django/forms/models.py", line 71, in save_m2m
f.save_form_data(instance, cleaned_data[f.name])

File "/var/lib/python-support/python2.5/django/db/models/fields/related.py", line 911, in save_form_data
setattr(instance, self.attname, data)

File "/var/lib/python-support/python2.5/django/db/models/fields/related.py", line 578, in set
manager.add(*value)

File "/var/lib/python-support/python2.5/django/db/models/fields/related.py", line 384, in add
self._add_items(self.source_col_name, self.target_col_name, *objs)

File "/var/lib/python-support/python2.5/django/db/models/fields/related.py", line 455, in _add_items
[self._pk_val, obj_id])

File "/var/lib/python-support/python2.5/django/db/backends/mysql/base.py", line 83, in execute return self.cursor.execute(query, args)

File "/var/lib/python-support/python2.5/MySQLdb/cursors.py", line 166, in execute
self.errorhandler(self, exc, value)

File "/var/lib/python-support/python2.5/MySQLdb/connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue

IntegrityError: (1062, "Duplicate entry '3' for key 2")

, POST:, COOKIES:{'__utma': '114731281.880071623.1276635043.1277298842.1277304949.6', '__utmb': '114731281.3.10.1277304949', '__utmc': '114731281', '__utmz': '114731281.1276635043.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)', 'sessionid': 'c3fd688bcca255f022b94d970aa8c765'}, META:{'AUTH_TYPE': None, 'CONTENT_LENGTH': 0L, 'CONTENT_TYPE': None, 'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_CHARSET': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'HTTP_ACCEPT_ENCODING': 'gzip,deflate', 'HTTP_ACCEPT_LANGUAGE': 'it-it,it;q=0.8,en-us;q=0.5,en;q=0.3', 'HTTP_CONNECTION': 'keep-alive', 'HTTP_CONTENT_LENGTH': '3626', 'HTTP_CONTENT_TYPE': 'multipart/form-data; boundary=---------------------------155190139316178193361399125485', 'HTTP_COOKIE': '__utma=114731281.880071623.1276635043.1277298842.1277304949.6; __utmz=114731281.1276635043.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); sessionid=c3fd688bcca255f022b94d970aa8c765; __utmc=114731281; __utmb=114731281.3.10.1277304949', 'HTTP_HOST': 'www.my_domain.tld', 'HTTP_KEEP_ALIVE': '115', 'HTTP_REFERER': 'http://www.my_domain.tld/admin/auth/user/3/', 'HTTP_USER_AGENT': 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; it; rv:1.9.2.4) Gecko/20100611 Firefox/3.6.4', 'PATH_INFO': u'/admin/auth/user/3/', 'PATH_TRANSLATED': None, 'QUERY_STRING': None, 'REMOTE_ADDR': '349.596.418.159', 'REMOTE_HOST': None, 'REMOTE_IDENT': None, 'REMOTE_USER': None, 'REQUEST_METHOD': 'POST', 'SCRIPT_NAME': '', 'SERVER_NAME': 'www.my_domain.tld', 'SERVER_PORT': 0, 'SERVER_PROTOCOL': 'HTTP/1.1', 'SERVER_SOFTWARE': 'mod_python'}>

Db validation says everything's fine. Another useful piece of data could be that I'm using a User Profile to store additional data.