Skip to content

Commit cad0ad0

Browse files
authored
set_roll_back should only rollback initialized connections
The exception handler call "connections.all()". This creates a database connection to all defined databases. As a small optimization you can use "connections.all(initialized_only=True)" to rollback only the database to which the current thread has open connections. (My application can have many databases defined, and this loop is identified as a source of many idle database connections)
1 parent dbac145 commit cad0ad0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

rest_framework/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def get_view_description(view, html=False):
6464

6565

6666
def set_rollback():
67-
for db in connections.all():
67+
for db in connections.all(initialized_only=True):
6868
if db.settings_dict['ATOMIC_REQUESTS'] and db.in_atomic_block:
6969
db.set_rollback(True)
7070

0 commit comments

Comments
 (0)