Fixed bug that caused KeyError in _commit_all_savepoints #34
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixed bug that caused KeyError in johnny.transaction.TransactionManager._commit_all_savepoints - issues #26 and #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:
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 (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.