Ticket #13870: django-terminate-isolating-transactions.patch

File django-terminate-isolating-transactions.patch, 2.2 KB (added by patrys, 5 years ago)

Partial workaround (see description)

  • django/db/backends/__init__.py

     
    5050        """
    5151        pass
    5252
     53    def _terminate_transaction_isolation(self, commited):
     54        """
     55        A hook for backend-specific changes required to reset the transaction
     56        isolation level.
     57        """
     58        pass
     59
    5360    def _savepoint(self, sid):
    5461        if not self.features.uses_savepoints:
    5562            return
  • django/db/backends/postgresql_psycopg2/base.py

     
    176176        if self.features.uses_autocommit and not managed and self.isolation_level:
    177177            self._set_isolation_level(0)
    178178
     179    def _terminate_transaction_isolation(self, commited):
     180        """
     181        The transaction is over so if the isolation level is not zero,
     182        terminate the isolating transaction.
     183        """
     184        if self.isolation_level and self.connection.get_transaction_status() == \
     185                psycopg2.extensions.TRANSACTION_STATUS_INTRANS:
     186            if commited:
     187                self.connection.commit()
     188            else:
     189                self.connection.rollback()
     190
    179191    def _set_isolation_level(self, level):
    180192        """
    181193        Do all the related feature configurations for changing isolation
  • django/db/transaction.py

     
    8484        raise TransactionManagementError("This code isn't under transaction management")
    8585    if dirty.get(thread_ident, {}).get(using, False):
    8686        rollback(using=using)
     87        connection._terminate_transaction_isolation(False)
    8788        raise TransactionManagementError("Transaction managed block ended with pending COMMIT/ROLLBACK")
     89    else:
     90        connection._terminate_transaction_isolation(True)
    8891    dirty[thread_ident][using] = False
    8992
    9093def is_dirty(using=None):
Back to Top