-
Notifications
You must be signed in to change notification settings - Fork 569
feat(django): Instrument database commits #5100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 11 commits
d2552ec
58ecb5b
ad5ef1d
7a82862
e8f664d
943e3bb
e397f65
3c4127c
7972103
639182d
2c90889
f9005dd
52fe140
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| import json | ||
| import threading | ||
|
|
||
| from django.db import transaction | ||
| from django.contrib.auth import login | ||
| from django.contrib.auth.models import User | ||
| from django.core.exceptions import PermissionDenied | ||
|
|
@@ -246,6 +247,27 @@ def postgres_select_orm(request, *args, **kwargs): | |
| return HttpResponse("ok {}".format(user)) | ||
|
|
||
|
|
||
| @csrf_exempt | ||
| def postgres_insert_orm_no_autocommit(request, *args, **kwargs): | ||
| transaction.set_autocommit(False, using="postgres") | ||
| user = User.objects.db_manager("postgres").create_user( | ||
| username="user1", | ||
| ) | ||
| transaction.commit(using="postgres") | ||
| transaction.set_autocommit(True, using="postgres") | ||
|
|
||
| return HttpResponse("ok {}".format(user)) | ||
|
|
||
|
|
||
| @csrf_exempt | ||
| def postgres_insert_orm_atomic(request, *args, **kwargs): | ||
| with transaction.atomic(using="postgres"): | ||
| user = User.objects.db_manager("postgres").create_user( | ||
| username="user1", | ||
| ) | ||
| return HttpResponse("ok {}".format(user)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Duplicate username causes IntegrityError on repeated callsBoth
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tests should be as deterministic as possible. The sample is intended to be very minimal. |
||
|
|
||
|
|
||
| @csrf_exempt | ||
| def permission_denied_exc(*args, **kwargs): | ||
| raise PermissionDenied("bye") | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.