From db7f748e722c7b1093f50908866c24ce14ac4cda Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Mon, 2 Jan 2012 06:44:55 -0400 Subject: [PATCH] Simplify database creation error catching for the history app --- apps/history/api.py | 44 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/apps/history/api.py b/apps/history/api.py index 03db0f15d4..04e212d3a2 100644 --- a/apps/history/api.py +++ b/apps/history/api.py @@ -3,15 +3,7 @@ from __future__ import absolute_import import pickle import json -try: - from psycopg2 import OperationalError -except ImportError: - class OperationalError(Exception): - pass - -from django.core.exceptions import ImproperlyConfigured from django.db import transaction -from django.db.utils import DatabaseError from django.core import serializers from django.shortcuts import get_object_or_404 from django.db import models @@ -20,33 +12,23 @@ from .models import HistoryType, History from .runtime_data import history_types_dict -@transaction.commit_manually +@transaction.commit_on_success def register_history_type(history_type_dict): namespace = history_type_dict['namespace'] name = history_type_dict['name'] - try: - # Permanent - history_type_obj, created = HistoryType.objects.get_or_create( - namespace=namespace, name=name) - history_type_obj.save() - # Runtime - history_types_dict.setdefault(namespace, {}) - history_types_dict[namespace][name] = { - 'label': history_type_dict['label'], - 'summary': history_type_dict.get('summary', u''), - 'details': history_type_dict.get('details', u''), - 'expressions': history_type_dict.get('expressions', []), - } - except DatabaseError: - transaction.rollback() - # Special case for ./manage.py syncdb - except (OperationalError, ImproperlyConfigured): - transaction.rollback() - # Special for DjangoZoom, which executes collectstatic media - # doing syncdb and creating the database tables - else: - transaction.commit() + history_type_obj, created = HistoryType.objects.get_or_create( + namespace=namespace, name=name) + history_type_obj.save() + + # Runtime + history_types_dict.setdefault(namespace, {}) + history_types_dict[namespace][name] = { + 'label': history_type_dict['label'], + 'summary': history_type_dict.get('summary', u''), + 'details': history_type_dict.get('details', u''), + 'expressions': history_type_dict.get('expressions', []), + } def create_history(history_type_dict, source_object=None, data=None):