from contextlib import contextmanager

from django.db import DatabaseError, IntegrityError, transaction


@contextmanager
def transaction_with_commit_on_errors():
    """Perform transaction and raise an error in any occurred."""
    error = None
    with transaction.atomic():
        try:
            yield
        except (DatabaseError, IntegrityError):
            raise
        except Exception as e:
            error = e
    if error:
        raise error

@@ -72,24 +72,8 @@
 ror,
- IntegrityError,
  tra
@@ -300,17 +300,16 @@
  except 
-(
 Database
@@ -317,25 +317,8 @@
 rror
-, IntegrityError)
 :%0A  

remove integrity error as it is a subclass of DatabaseError