Ticket #15901: django-db-exceptions.patch

File django-db-exceptions.patch, 2.3 KB (added by gcbirzan, 8 years ago)
  • django/db/backends/postgresql_psycopg2/base.py

    diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py
    index 61be680..e99fcc7 100644
    a b psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) 
    3131psycopg2.extensions.register_adapter(SafeString, psycopg2.extensions.QuotedString)
    3232psycopg2.extensions.register_adapter(SafeUnicode, psycopg2.extensions.QuotedString)
    3333
     34utils.IntegrityError.register(Database.IntegrityError)
     35utils.DatabaseError.register(Database.DatabaseError)
     36
    3437logger = getLogger('django.db.backends')
    3538
    3639def utc_tzinfo_factory(offset):
    class CursorWrapper(object): 
    4750    def __init__(self, cursor):
    4851        self.cursor = cursor
    4952
    50     def execute(self, query, args=None):
    51         try:
    52             return self.cursor.execute(query, args)
    53         except Database.IntegrityError as e:
    54             raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
    55         except Database.DatabaseError as e:
    56             raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
    57 
    58     def executemany(self, query, args):
    59         try:
    60             return self.cursor.executemany(query, args)
    61         except Database.IntegrityError as e:
    62             raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]
    63         except Database.DatabaseError as e:
    64             raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]
    65 
    6653    def __getattr__(self, attr):
    6754        if attr in self.__dict__:
    6855            return self.__dict__[attr]
  • django/db/utils.py

    diff --git a/django/db/utils.py b/django/db/utils.py
    index 2b6ae2c..52f8188 100644
    a b  
    11import os
    22from threading import local
    33
     4from abc import ABCMeta
     5
    46from django.conf import settings
    57from django.core.exceptions import ImproperlyConfigured
    68from django.utils.importlib import import_module
    DEFAULT_DB_ALIAS = 'default' 
    1214# We will rethrow any backend-specific errors using these
    1315# common wrappers
    1416class DatabaseError(Exception):
    15     pass
     17    __metaclass__ = ABCMeta
    1618
    1719class IntegrityError(DatabaseError):
    18     pass
     20    __metaclass__ = ABCMeta
    1921
    2022
    2123def load_backend(backend_name):
Back to Top