File tree Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Expand file tree Collapse file tree 1 file changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -158,15 +158,22 @@ def __enter__(self):
158
158
return self
159
159
160
160
def __exit__ (self , error_type , error_value , traceback ):
161
- """End a transaction by committing or rolling back."""
162
- if error_type is None :
163
- try :
164
- self .commit ()
165
- except Exception :
166
- with safe_reraise ():
167
- self .rollback ()
168
- else :
169
- self .rollback ()
161
+ """End a transaction by committing or rolling back. Close local connection"""
162
+ try :
163
+ if error_type is None :
164
+ try :
165
+ self .commit ()
166
+ except Exception :
167
+ with safe_reraise ():
168
+ self .rollback ()
169
+ else :
170
+ self .rollback ()
171
+ except Exception :
172
+ raise
173
+ finally :
174
+ tx_conn = self .connections .pop (threading .get_ident (), None )
175
+ if tx_conn is not None :
176
+ tx_conn .close ()
170
177
171
178
def close (self ):
172
179
"""Close database connections. Makes this object unusable."""
You can’t perform that action at this time.
0 commit comments