From 9731b2f1dca94731fd2acf7f628c200e2d819a41 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Mon, 12 Mar 2012 22:47:55 -0400 Subject: [PATCH] Add additional consistency check during document creation For databases that doesn't support transactions --- apps/sources/models.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/sources/models.py b/apps/sources/models.py index ebc794bcfb..178ae179b9 100644 --- a/apps/sources/models.py +++ b/apps/sources/models.py @@ -129,10 +129,19 @@ class BaseModel(models.Model): try: new_version = document.new_version(file=file_object, **new_version_data) - except Exception: + except Exception, exc: + logger.error('Unhandled exception: %s' % exc) # Don't leave the database in a broken state - # document.delete() + # Delete invalid documents with no version child + # For databases that doesn't support transactions, delete the document + if document.version_set.count() == 0: + logger.debug('Empty document with no previous versions, deleting.') + document.delete() + # Rollback everything in case the database DOES support + # transactions transaction.rollback() + # Re-raise the error so that the view can capture + # and display it raise if filename: