Opened 16 years ago

Closed 12 years ago

#10744 closed Bug (fixed)

transaction.leave_transaction_management leaks

Reported by: Glenn Maynard Owned by: Aymeric Augustin
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

leave_transaction_management removes threads from state, but not dirty. This will cause a leak as threads are destroyed, and causes the set_clean and set_dirty sanity check ("This code isn't under transaction management") to not always trigger. It may also cause problems if created threads get the same thread identifier as a previous thread. Attached patch cleans up the transaction state when exiting transaction management; obviously, TLS would be a cleaner and more reliable solution.

This patch causes a failure in regressiontests.cache.tests.DBCacheTests:

======================================================================
ERROR: test_add (regressiontests.cache.tests.DBCacheTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/glenn/django/tests/regressiontests/cache/tests.py", line 142, in test_add
    result = self.cache.add("addkey1", "newvalue")
  File "/home/glenn/django/django/core/cache/backends/db.py", line 45, in add
    return self._base_set('add', key, value, timeout)
  File "/home/glenn/django/django/core/cache/backends/db.py", line 68, in _base_set
    transaction.rollback()
  File "/home/glenn/django/django/db/transaction.py", line 180, in rollback
    set_clean()
  File "/home/glenn/django/django/db/transaction.py", line 114, in set_clean
    raise TransactionManagementError("This code isn't under transaction management")
TransactionManagementError: This code isn't under transaction management

I don't know what _base_set should be doing, but it seems like this error is intended to be triggered in this situation.

Attachments (1)

cleanup-transaction-state-on-exit.diff (698 bytes ) - added by Glenn Maynard 16 years ago.

Download all attachments as: .zip

Change History (7)

by Glenn Maynard, 16 years ago

comment:1 by Alex Gaynor, 15 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Chris Beaven, 14 years ago

Severity: Normal
Type: Bug

comment:3 by patchhammer, 14 years ago

Easy pickings: unset
Patch needs improvement: set

cleanup-transaction-state-on-exit.diff fails to apply cleanly on to trunk

comment:4 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:5 by Aymeric Augustin, 12 years ago

Owner: changed from nobody to Aymeric Augustin
Status: newassigned

comment:6 by Aymeric Augustin <aymeric.augustin@…>, 12 years ago

Resolution: fixed
Status: assignedclosed

In 14cddf51c5f001bb426ce7f7a83fdc52c8d8aee9:

Merged branch 'database-level-autocommit'.

Fixed #2227: atomic supports nesting.
Fixed #6623: commit_manually is deprecated and atomic doesn't suffer from this defect.
Fixed #8320: the problem wasn't identified, but the legacy transaction management is deprecated.
Fixed #10744: the problem wasn't identified, but the legacy transaction management is deprecated.
Fixed #10813: since autocommit is enabled, it isn't necessary to rollback after errors any more.
Fixed #13742: savepoints are now implemented for SQLite.
Fixed #13870: transaction management in long running processes isn't a problem any more, and it's documented.
Fixed #14970: while it digresses on transaction management, this ticket essentially asks for autocommit on PostgreSQL.
Fixed #15694: atomic supports nesting.
Fixed #17887: autocommit makes it impossible for a connection to stay "idle of transaction".

Note: See TracTickets for help on using tickets.
Back to Top