#2227: transaction.commit()/rollback() should be aware of nested calls to transaction.managed(True) -------------------------------------+------------------------------------- Reporter: mderk@… | Owner: nobody Type: New feature | Status: assigned Component: Database layer | Version: master (models, ORM) | Resolution: Severity: Normal | Triage Stage: Accepted Keywords: transaction, nest, | Needs documentation: 0 scope, nested, rollback, commit | Patch needs improvement: 1 Has patch: 1 | UI/UX: 0 Needs tests: 0 | Easy pickings: 0 | -------------------------------------+-------------------------------------
Comment (by mlarente): The concurrency issue can be fixed by using a thread-local stack, such as this: {{{ import threading _atomic_state = threading.local() def atomic(using=None): def entering(using): if not hasattr(_atomic_state, 'sid_stack'): _atomic_state.sid_stack = [] sid = None if is_managed(using=using): sid = savepoint(using=using) else: enter_transaction_management(using=using) managed(True, using=using) _atomic_state.sid_stack.append(sid) def exiting(exc_value, using): sid = _atomic_state.sid_stack.pop() if sid is not None: if exc_value is not None: savepoint_rollback(sid, using=using) else: try: if exc_value is not None: if is_dirty(using=using): rollback(using=using) else: if is_dirty(using=using): try: commit(using=using) except: rollback(using=using) raise finally: leave_transaction_management(using=using) return _transaction_func(entering, exiting, using) }}} -- Ticket URL: <https://code.djangoproject.com/ticket/2227#comment:36> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.