Skip to content

Commit

Permalink
set_roll_back should only rollback initialized connections
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
jdetaeye authored Dec 9, 2024
1 parent dbac145 commit cad0ad0
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion rest_framework/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_view_description(view, html=False):


def set_rollback():
for db in connections.all():
for db in connections.all(initialized_only=True):
if db.settings_dict['ATOMIC_REQUESTS'] and db.in_atomic_block:
db.set_rollback(True)

Expand Down

0 comments on commit cad0ad0

Please sign in to comment.