Skip to content

Commit 943e3bb

Browse files
.
1 parent e8f664d commit 943e3bb

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

tests/integrations/django/myapp/urls.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ def path(path, *args, **kwargs):
6262
path("postgres-select", views.postgres_select, name="postgres_select"),
6363
path("postgres-select-slow", views.postgres_select_orm, name="postgres_select_orm"),
6464
path(
65-
"postgres-select-no-autocommit",
66-
views.postgres_select_orm_no_autocommit,
67-
name="postgres_select_orm_no_autocommit",
65+
"postgres-insert-no-autocommit",
66+
views.postgres_insert_orm_no_autocommit,
67+
name="postgres_insert_orm_no_autocommit",
6868
),
6969
path(
70-
"postgres-select-atomic",
71-
views.postgres_select_orm_atomic,
72-
name="postgres_select_orm_atomic",
70+
"postgres-insert-atomic",
71+
views.postgres_insert_orm_atomic,
72+
name="postgres_insert_orm_atomic",
7373
),
7474
path(
7575
"postgres-select-slow-from-supplement",

tests/integrations/django/myapp/views.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,23 @@ def postgres_select_orm(request, *args, **kwargs):
248248

249249

250250
@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()
251+
def postgres_insert_orm_no_autocommit(request, *args, **kwargs):
252+
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")
258+
255259
return HttpResponse("ok {}".format(user))
256260

257261

258262
@csrf_exempt
259-
def postgres_select_orm_atomic(request, *args, **kwargs):
260-
with transaction.atomic():
261-
user = User.objects.using("postgres").all().first()
263+
def postgres_insert_orm_atomic(request, *args, **kwargs):
264+
with transaction.atomic(using="postgres"):
265+
user = User.objects.db_manager("postgres").create_user(
266+
username="user1",
267+
)
262268
return HttpResponse("ok {}".format(user))
263269

264270

0 commit comments

Comments
 (0)