@@ -68,12 +68,12 @@ def __enter__(self):
68
68
# Pretend we're already in an atomic block to bypass the code
69
69
# that disables autocommit to enter a transaction, and make a
70
70
# note to deal with this case in __exit__.
71
- connection .in_atomic_block_mongo = True
72
- connection .commit_on_exit = False
71
+ # connection.in_atomic_block_mongo = True
72
+ # connection.commit_on_exit = False
73
73
74
74
if connection .in_atomic_block_mongo :
75
- # We're already in a transaction
76
- pass
75
+ # We're already in a transaction. Increment the number of nested atomics.
76
+ connection . nested_atomics += 1
77
77
else :
78
78
connection ._start_transaction (
79
79
False , force_begin_transaction_with_broken_autocommit = True
@@ -89,25 +89,23 @@ def __exit__(self, exc_type, exc_value, traceback):
89
89
if connection .in_atomic_block_mongo :
90
90
connection .atomic_blocks_mongo .pop ()
91
91
92
- # Prematurely unset this flag to allow using commit or rollback.
93
- connection ._in_atomic_block = False
92
+ if connection .nested_atomics :
93
+ connection .nested_atomics -= 1
94
+ else :
95
+ # Prematurely unset this flag to allow using commit or rollback.
96
+ connection .in_atomic_block_mongo = False
94
97
try :
95
- if connection .closed_in_transaction :
96
- # The database will perform a rollback by itself.
97
- # Wait until we exit the outermost block.
98
- pass
99
-
100
- elif exc_type is None and not connection .needs_rollback_mongo :
101
- if connection ._in_atomic_block :
98
+ if exc_type is None and not connection .needs_rollback_mongo :
99
+ if connection .in_atomic_block_mongo :
102
100
# Release savepoint if there is one
103
101
pass
104
102
else :
105
103
# Commit transaction
106
104
try :
107
- connection ._commit_transaction ()
105
+ connection .commit_mongo ()
108
106
except DatabaseError :
109
107
try :
110
- connection ._rollback_transaction ()
108
+ connection .rollback_mongo ()
111
109
except Error :
112
110
# An error during rollback means that something
113
111
# went wrong with the connection. Drop it.
@@ -123,24 +121,19 @@ def __exit__(self, exc_type, exc_value, traceback):
123
121
else :
124
122
# Roll back transaction
125
123
try :
126
- connection ._rollback_transaction ()
124
+ connection .rollback_mongo ()
127
125
except Error :
128
126
# An error during rollback means that something
129
127
# went wrong with the connection. Drop it.
130
128
connection .close ()
131
129
finally :
132
130
# Outermost block exit when autocommit was enabled.
133
131
if not connection .in_atomic_block_mongo :
134
- if connection .closed_in_transaction :
135
- connection .connection = None
136
- # else:
137
- # connection.set_autocommit(True)
132
+ pass
133
+ # connection.set_autocommit(True)
138
134
# Outermost block exit when autocommit was disabled.
139
135
elif not connection .commit_on_exit :
140
- if connection .closed_in_transaction :
141
- connection .connection = None
142
- else :
143
- connection .in_atomic_block_mongo = False
136
+ connection .in_atomic_block_mongo = False
144
137
145
138
146
139
def atomic (using = None , durable = False ):
0 commit comments