~ubuntu-branches/ubuntu/saucy/python-django/saucy-updates

« back to all changes in this revision

Viewing changes to django/middleware/transaction.py

  • Committer: Package Import Robot
  • Author(s): Raphaël Hertzog
  • Date: 2013-02-24 10:28:08 UTC
  • mfrom: (1.1.20) (4.4.26 sid)
  • Revision ID: package-import@ubuntu.com-20130224102808-mtc8rkfx42wro0oz
Tags: 1.4.5-1
* New upstream maintenance release dropping some undesired .pyc files
  and fixing a documentation link.
* High urgency due to former security updates.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
    def process_exception(self, request, exception):
16
16
        """Rolls back the database and leaves transaction management"""
17
17
        if transaction.is_dirty():
 
18
            # This rollback might fail because of network failure for example.
 
19
            # If rollback isn't possible it is impossible to clean the
 
20
            # connection's state. So leave the connection in dirty state and
 
21
            # let request_finished signal deal with cleaning the connection.
18
22
            transaction.rollback()
19
23
        transaction.leave_transaction_management()
20
24
 
22
26
        """Commits and leaves transaction management."""
23
27
        if transaction.is_managed():
24
28
            if transaction.is_dirty():
25
 
                transaction.commit()
 
29
                # Note: it is possible that the commit fails. If the reason is
 
30
                # closed connection or some similar reason, then there is
 
31
                # little hope to proceed nicely. However, in some cases (
 
32
                # deferred foreign key checks for exampl) it is still possible
 
33
                # to rollback().
 
34
                try:
 
35
                    transaction.commit()
 
36
                except Exception:
 
37
                    # If the rollback fails, the transaction state will be
 
38
                    # messed up. It doesn't matter, the connection will be set
 
39
                    # to clean state after the request finishes. And, we can't
 
40
                    # clean the state here properly even if we wanted to, the
 
41
                    # connection is in transaction but we can't rollback...
 
42
                    transaction.rollback()
 
43
                    transaction.leave_transaction_management()
 
44
                    raise
26
45
            transaction.leave_transaction_management()
27
46
        return response