Add transaction rollback
This commit is contained in:
@@ -22,6 +22,7 @@ class LockManager(models.Manager):
|
|||||||
logger.debug('acquired lock: %s' % name)
|
logger.debug('acquired lock: %s' % name)
|
||||||
return lock
|
return lock
|
||||||
except IntegrityError, msg:
|
except IntegrityError, msg:
|
||||||
|
transaction.rollback()
|
||||||
logger.debug('IntegrityError: %s', msg)
|
logger.debug('IntegrityError: %s', msg)
|
||||||
# There is already an existing lock
|
# There is already an existing lock
|
||||||
# Check it's expiration date and if expired, reset it
|
# Check it's expiration date and if expired, reset it
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
from django.utils.translation import ugettext
|
from django.utils.translation import ugettext
|
||||||
from django.db.models.signals import post_save, post_syncdb
|
from django.db.models.signals import post_save, post_syncdb
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
from django.db.utils import DatabaseError
|
||||||
|
|
||||||
from navigation.api import register_links, register_multi_item_links
|
from navigation.api import register_links, register_multi_item_links
|
||||||
from documents.models import Document, DocumentVersion
|
from documents.models import Document, DocumentVersion
|
||||||
@@ -64,10 +65,14 @@ register_maintenance_links([all_document_ocr_cleanup], namespace='ocr', title=_(
|
|||||||
|
|
||||||
@transaction.commit_on_success
|
@transaction.commit_on_success
|
||||||
def create_default_queue():
|
def create_default_queue():
|
||||||
default_queue, created = DocumentQueue.objects.get_or_create(name='default')
|
try:
|
||||||
if created:
|
default_queue, created = DocumentQueue.objects.get_or_create(name='default')
|
||||||
default_queue.label = ugettext(u'Default')
|
except DatabaseError:
|
||||||
default_queue.save()
|
transaction.rollback()
|
||||||
|
else:
|
||||||
|
if created:
|
||||||
|
default_queue.label = ugettext(u'Default')
|
||||||
|
default_queue.save()
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, dispatch_uid='document_post_save', sender=DocumentVersion)
|
@receiver(post_save, dispatch_uid='document_post_save', sender=DocumentVersion)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from django.contrib.contenttypes.models import ContentType
|
|||||||
from django.contrib.contenttypes import generic
|
from django.contrib.contenttypes import generic
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
from django.db.utils import DatabaseError
|
||||||
|
|
||||||
from converter.api import get_available_transformations_choices
|
from converter.api import get_available_transformations_choices
|
||||||
from converter.literals import DIMENSION_SEPARATOR
|
from converter.literals import DIMENSION_SEPARATOR
|
||||||
@@ -93,7 +94,7 @@ class BaseModel(models.Model):
|
|||||||
document = Document()
|
document = Document()
|
||||||
if document_type:
|
if document_type:
|
||||||
document.document_type = document_type
|
document.document_type = document_type
|
||||||
document.save()
|
document.save()
|
||||||
|
|
||||||
apply_default_acls(document, user)
|
apply_default_acls(document, user)
|
||||||
|
|
||||||
@@ -119,7 +120,8 @@ class BaseModel(models.Model):
|
|||||||
new_version = document.new_version(file=file_object, **new_version_data)
|
new_version = document.new_version(file=file_object, **new_version_data)
|
||||||
except Exception:
|
except Exception:
|
||||||
# Don't leave the database in a broken state
|
# Don't leave the database in a broken state
|
||||||
document.delete()
|
# document.delete()
|
||||||
|
transaction.rollback()
|
||||||
raise
|
raise
|
||||||
|
|
||||||
if filename:
|
if filename:
|
||||||
|
|||||||
Reference in New Issue
Block a user