Ticket #12293: django-ignore-mysql-notes.patch

File django-ignore-mysql-notes.patch, 1.9 KB (added by Walter Doekes, 15 years ago)

Ignore 'Note'-level warnings from mysqldb.

  • django/db/backends/mysql/base.py

    old new  
    8080        self.cursor = cursor
    8181
    8282    def execute(self, query, args=None):
    83         try:
    84             return self.cursor.execute(query, args)
    85         except Database.OperationalError, e:
    86             # Map some error codes to IntegrityError, since they seem to be
    87             # misclassified and Django would prefer the more logical place.
    88             if e[0] in self.codes_for_integrityerror:
    89                 raise Database.IntegrityError(tuple(e))
    90             raise
     83        return self._execute_and_catch(self.cursor.execute, query, args)
    9184
    9285    def executemany(self, query, args):
     86        return self._execute_and_catch(self.cursor.executemany, query, args)
     87
     88    def _execute_and_catch(self, execute_func, query, args):
    9389        try:
    94             return self.cursor.executemany(query, args)
     90            return execute_func(query, args)
    9591        except Database.OperationalError, e:
    9692            # Map some error codes to IntegrityError, since they seem to be
    9793            # misclassified and Django would prefer the more logical place.
    9894            if e[0] in self.codes_for_integrityerror:
    9995                raise Database.IntegrityError(tuple(e))
    10096            raise
     97        except Database.Warning, e:
     98            try:
     99                # Some warnings really are Notes, like with an DROP TABLE IF EXISTS.
     100                # We don't want to raise those.
     101                warnings = self.cursor.connection.show_warnings()
     102                if not (False in [i[0] == 'Note' for i in warnings]): # older python lacks any()
     103                    return None
     104            except AttributeError: # older mysql does not have show_warnings()
     105                pass
     106            raise
    101107
    102108    def __getattr__(self, attr):
    103109        if attr in self.__dict__:
Back to Top