-
Notifications
You must be signed in to change notification settings - Fork 570
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
Changes from 12 commits
d2552ec
58ecb5b
ad5ef1d
7a82862
e8f664d
943e3bb
e397f65
3c4127c
7972103
639182d
2c90889
f9005dd
52fe140
6896522
cfc9b7f
9b503a0
f586a56
f0f7b40
b0b9bd7
3ccd0c3
89c9594
2668f4e
28d7050
485dc4a
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)) | ||
alexander-alderman-webb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @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.