Do not "pass" on DatabseError
exceptions in signal processors. Bad example:
@receiver(post_save, sender=User, dispatch_uid='user_post_save')
def user_post_save(sender, instance, created, raw, **kwargs):
if created and not raw:
try:
try:
flatpage = FlatPage.objects.get(url='/my_page/')
except FlatPage.DoesNotExist:
flatpage = FlatPage.objects.create(**DEFAULT_PAGE)
user = instance
notify.send(user, recipient=user, verb="flatpage", target=flatpage)
except DatabaseError:
pass
I tried to use pass in this example because syncdb failes for sqlite and "passing" fixed that problem.
But postgresql will still fail with "Transaction aborted" if you just pass this exception. You should rollback transaction to make it work:
from django.db import transaction
@receiver(post_save, sender=User, dispatch_uid='user_post_save')
def user_post_save(sender, instance, created, raw, **kwargs):
if created and not raw:
with transaction.commit_on_success():
try:
try:
flatpage = FlatPage.objects.get(url='/my_page/')
except FlatPage.DoesNotExist:
flatpage = FlatPage.objects.create(**DEFAULT_PAGE)
user = instance
notify.send(user, recipient=user, verb="flatpage", target=flatpage)
except DatabaseError:
transaction.rollback()