Ticket #29257: ticket29257.diff

File ticket29257.diff, 1005 bytes (added by Chetan Khanna, 5 years ago)

patch_without_test

  • django/db/models/sql/compiler.py

    diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py
    index 9433540d7c..6892f95617 100644
    a b class SQLCompiler:  
    11381138            cursor = self.connection.cursor()
    11391139        try:
    11401140            cursor.execute(sql, params)
    1141         except Exception:
     1141        except Exception as e:
    11421142            # Might fail for server-side cursors (e.g. connection closed)
    1143             cursor.close()
    1144             raise
     1143            try:
     1144                cursor.close()
     1145            except Exception:
     1146                # If we got an error creating the cursor, then closing it
     1147                # will always fail. Raise the outer exception instead of the
     1148                # obscure "cursor _django_curs_xxxx does not exist".
     1149                raise e from None
     1150            else:
     1151                raise e
    11451152
    11461153        if result_type == CURSOR:
    11471154            # Give the caller the cursor to process and close.
Back to Top