Issue #5 resolved

IntegrityErrors in utils.py

Jakub Wiśniowski
created an issue

There is a common pattern in utils.py to catch IntegrityError exceptions. It is ok with sqlite but not with Postgres - there IntegrityError breaks whole transaction. So my proposal is to replace code like (from register_permission): {{{

!python

try: p = Permission.objects.create(name=name, codename=codename) p.content_types = ctypes p.save() except IntegrityError: return False }}}

with

{{{

!python

p, created = Permission.objects.get_or_create(name=name, codename=codename)
p.content_types = ctypes
p.save()

}}}

It's not perfect but it's simple and works well with multiple calls to register_permission (group, role) functions.

Comments (2)

  1. Log in to comment