Fixed bug that caused KeyError in johnny.transaction.TransactionManager._commit_savepoint - issue #30 on Github (#69 on Bitbucket)
Fixed bug that caused KeyError in johnny.transaction.TransactionManager._commit_savepoint - issue #30 on Github (#69 on Bitbucket)

This patch is fixing cause of the problem, not hiding it as pull requests #26 and #30.

To reproduce cause of the problem you should:
1) Enable QueryCacheMiddleware
2) Work in unmanaged transaction state (it means autocommit mode, i.e. without 'django.middleware.transaction.TransactionMiddleware' and not within 'transaction.enter_transaction_management()' block)
3) Create a savepoint and then try to save some object (it is done by 'django.db.models.query.QuerySet#get_or_create' or by 'django.contrib.sessions.backends.db.SessionStore#save')

The essence of the problem is the fact that Django ORM widely uses a 'django/db/transaction.py#commit_unless_managed' (which is unpatched by Johny Cache) function instead of 'django/db/transaction.py#commit_unless_managed' (which is patched by Johny Cache). So, when we working in unmanaged transaction state Johny Cache will still register savepoints upon creation but will be unable to handle commits and rollbacks that wast performed by 'unless_managed' functions. Since Django is using dumb algorithm for savepoint names generation (they reuse same names within thread once they were commited) it will lead to a situation when Johny Cache will register several savepoints with same name within one transaction and fail when it will try to commit or rollback them.

Proposed solution adds patching to 'django/db/transaction.py#commit_unless_managed' and 'django/db/transaction.py#rollback_unless_managed' functions in the same way as it was done for 'django/db/transaction.py#commit' and 'django/db/transaction.py#rollback' functions with one difference - additional check whether current transaction is unmanaged.
BertrandBordage/johnny-cache,jmoiron/johnny-cache