From 7fa51a24a8ca47f41f5d711e81b8a71b08542a36 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sat, 21 Jul 2012 21:06:13 +0200 Subject: [PATCH] [py3] Exception aren't iterable in Python 3. --- django/db/backends/mysql/base.py | 16 ++++++++-------- django/db/backends/oracle/base.py | 18 +++++++++--------- django/db/backends/postgresql_psycopg2/base.py | 10 +++++----- django/db/backends/sqlite3/base.py | 8 ++++---- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index 201fed66a6e..9f5b9f5b77b 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -118,29 +118,29 @@ class CursorWrapper(object): try: return self.cursor.execute(query, args) except Database.IntegrityError as e: - six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2]) except Database.OperationalError as e: # Map some error codes to IntegrityError, since they seem to be # misclassified and Django would prefer the more logical place. if e[0] in self.codes_for_integrityerror: - six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]) - six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2]) + six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2]) except Database.DatabaseError as e: - six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2]) def executemany(self, query, args): try: return self.cursor.executemany(query, args) except Database.IntegrityError as e: - six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2]) except Database.OperationalError as e: # Map some error codes to IntegrityError, since they seem to be # misclassified and Django would prefer the more logical place. if e[0] in self.codes_for_integrityerror: - six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]) - six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2]) + six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2]) except Database.DatabaseError as e: - six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2]) def __getattr__(self, attr): if attr in self.__dict__: diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 705ae30ccc6..88a243a46d3 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -550,7 +550,7 @@ class DatabaseWrapper(BaseDatabaseWrapper): except Database.IntegrityError as e: # In case cx_Oracle implements (now or in a future version) # raising this specific exception - six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2]) except Database.DatabaseError as e: # cx_Oracle 5.0.4 raises a cx_Oracle.DatabaseError exception # with the following attributes and values: @@ -562,8 +562,8 @@ class DatabaseWrapper(BaseDatabaseWrapper): x = e.args[0] if hasattr(x, 'code') and hasattr(x, 'message') \ and x.code == 2091 and 'ORA-02291' in x.message: - six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]) - six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2]) + six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2]) class OracleParam(object): @@ -689,12 +689,12 @@ class FormatStylePlaceholderCursor(object): try: return self.cursor.execute(query, self._param_generator(params)) except Database.IntegrityError as e: - six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2]) except Database.DatabaseError as e: # cx_Oracle <= 4.4.0 wrongly raises a DatabaseError for ORA-01400. if hasattr(e.args[0], 'code') and e.args[0].code == 1400 and not isinstance(e, IntegrityError): - six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]) - six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2]) + six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2]) def executemany(self, query, params=None): # cx_Oracle doesn't support iterators, convert them to lists @@ -718,12 +718,12 @@ class FormatStylePlaceholderCursor(object): return self.cursor.executemany(query, [self._param_generator(p) for p in formatted]) except Database.IntegrityError as e: - six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2]) except Database.DatabaseError as e: # cx_Oracle <= 4.4.0 wrongly raises a DatabaseError for ORA-01400. if hasattr(e.args[0], 'code') and e.args[0].code == 1400 and not isinstance(e, IntegrityError): - six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]) - six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2]) + six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2]) def fetchone(self): row = self.cursor.fetchone() diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index 8b21b8ceb88..d553594ec1c 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -52,17 +52,17 @@ class CursorWrapper(object): try: return self.cursor.execute(query, args) except Database.IntegrityError as e: - six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2]) except Database.DatabaseError as e: - six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2]) def executemany(self, query, args): try: return self.cursor.executemany(query, args) except Database.IntegrityError as e: - six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2]) except Database.DatabaseError as e: - six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2]) def __getattr__(self, attr): if attr in self.__dict__: @@ -237,4 +237,4 @@ class DatabaseWrapper(BaseDatabaseWrapper): try: return self.connection.commit() except Database.IntegrityError as e: - six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2]) diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index 4c7b881e110..e2149ca8d8f 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -349,18 +349,18 @@ class SQLiteCursorWrapper(Database.Cursor): try: return Database.Cursor.execute(self, query, params) except Database.IntegrityError as e: - six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2]) except Database.DatabaseError as e: - six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2]) def executemany(self, query, param_list): query = self.convert_query(query) try: return Database.Cursor.executemany(self, query, param_list) except Database.IntegrityError as e: - six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.IntegrityError, utils.IntegrityError(*tuple(e.args)), sys.exc_info()[2]) except Database.DatabaseError as e: - six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2]) + six.reraise(utils.DatabaseError, utils.DatabaseError(*tuple(e.args)), sys.exc_info()[2]) def convert_query(self, query): return FORMAT_QMARK_REGEX.sub('?', query).replace('%%','%')