Skip to content

Commit 52fe140

Browse files
try-finally for resetting autocommit
1 parent f9005dd commit 52fe140

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

tests/integrations/django/myapp/views.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,13 @@ def postgres_select_orm(request, *args, **kwargs):
250250
@csrf_exempt
251251
def postgres_insert_orm_no_autocommit(request, *args, **kwargs):
252252
transaction.set_autocommit(False, using="postgres")
253-
user = User.objects.db_manager("postgres").create_user(
254-
username="user1",
255-
)
256-
transaction.commit(using="postgres")
257-
transaction.set_autocommit(True, using="postgres")
253+
try:
254+
user = User.objects.db_manager("postgres").create_user(
255+
username="user1",
256+
)
257+
transaction.commit(using="postgres")
258+
finally:
259+
transaction.set_autocommit(True, using="postgres")
258260

259261
return HttpResponse("ok {}".format(user))
260262

0 commit comments

Comments
 (0)