Skip to content

Commit 58ecb5b

Browse files
.
1 parent d2552ec commit 58ecb5b

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

tests/integrations/django/myapp/urls.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ def path(path, *args, **kwargs):
6161
path("template-test4", views.template_test4, name="template_test4"),
6262
path("postgres-select", views.postgres_select, name="postgres_select"),
6363
path("postgres-select-slow", views.postgres_select_orm, name="postgres_select_orm"),
64+
path(
65+
"postgres-select-no-autocommit",
66+
views.postgres_select_orm_no_autocommit,
67+
name="postgres_select_orm_no_autocommit",
68+
),
69+
path(
70+
"postgres-select-atomic",
71+
views.postgres_select_orm_atomic,
72+
name="postgres_select_orm_atomic",
73+
),
6474
path(
6575
"postgres-select-slow-from-supplement",
6676
helper_views.postgres_select_orm,

tests/integrations/django/myapp/views.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import threading
44

5+
from django.db import transaction
56
from django.contrib.auth import login
67
from django.contrib.auth.models import User
78
from django.core.exceptions import PermissionDenied
@@ -246,6 +247,21 @@ def postgres_select_orm(request, *args, **kwargs):
246247
return HttpResponse("ok {}".format(user))
247248

248249

250+
@csrf_exempt
251+
def postgres_select_orm_no_autocommit(request, *args, **kwargs):
252+
transaction.set_autocommit(False)
253+
user = User.objects.using("postgres").all().first()
254+
transaction.commit()
255+
return HttpResponse("ok {}".format(user))
256+
257+
258+
@csrf_exempt
259+
def postgres_select_orm_atomic(request, *args, **kwargs):
260+
with transaction.atomic():
261+
user = User.objects.using("postgres").all().first()
262+
return HttpResponse("ok {}".format(user))
263+
264+
249265
@csrf_exempt
250266
def permission_denied_exc(*args, **kwargs):
251267
raise PermissionDenied("bye")

0 commit comments

Comments
 (0)