~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to django/middleware/transaction.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-11-07 15:33:49 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131107153349-e31sc149l2szs3jb
Tags: 1.6-1
* New upstream version. Closes: #557474, #724637.
* python-django now also suggests the installation of ipython,
  bpython, python-django-doc, and libgdal1.
  Closes: #636511, #686333, #704203
* Set package maintainer to Debian Python Modules Team.
* Bump standards version to 3.9.5, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from django.db import transaction
 
1
import warnings
 
2
 
 
3
from django.core.exceptions import MiddlewareNotUsed
 
4
from django.db import connection, transaction
2
5
 
3
6
class TransactionMiddleware(object):
4
7
    """
7
10
    commit, the commit is done when a successful response is created. If an
8
11
    exception happens, the database is rolled back.
9
12
    """
 
13
 
 
14
    def __init__(self):
 
15
        warnings.warn(
 
16
            "TransactionMiddleware is deprecated in favor of ATOMIC_REQUESTS.",
 
17
            PendingDeprecationWarning, stacklevel=2)
 
18
        if connection.settings_dict['ATOMIC_REQUESTS']:
 
19
            raise MiddlewareNotUsed
 
20
 
10
21
    def process_request(self, request):
11
22
        """Enters transaction management"""
12
23
        transaction.enter_transaction_management()
13
 
        transaction.managed(True)
14
24
 
15
25
    def process_exception(self, request, exception):
16
26
        """Rolls back the database and leaves transaction management"""
24
34
 
25
35
    def process_response(self, request, response):
26
36
        """Commits and leaves transaction management."""
27
 
        if transaction.is_managed():
 
37
        if not transaction.get_autocommit():
28
38
            if transaction.is_dirty():
29
39
                # Note: it is possible that the commit fails. If the reason is
30
40
                # closed connection or some similar reason, then there is