Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
9666874e
Kaydet (Commit)
9666874e
authored
May 17, 2013
tarafından
Marc Tamlyn
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Tidy up some of the transaction documentation.
üst
838f2897
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
18 deletions
+22
-18
transactions.txt
docs/topics/db/transactions.txt
+22
-18
No files found.
docs/topics/db/transactions.txt
Dosyayı görüntüle @
9666874e
...
@@ -92,19 +92,15 @@ Django provides a single API to control database transactions.
...
@@ -92,19 +92,15 @@ Django provides a single API to control database transactions.
.. function:: atomic(using=None, savepoint=True)
.. function:: atomic(using=None, savepoint=True)
This function creates an atomic block for writes to the database.
Atomicity is the defining property of database transactions. ``atomic``
(Atomicity is the defining property of database transactions.)
allows us to create a block of code within which the atomicity on the
database is guaranteed. If the block of code is successfully completed, the
changes are committed to the database. If there is an exception, the
changes are rolled back.
When the block completes successfully, the changes are committed to the
``atomic`` blocks can be nested. In this case, when an inner block
database. When it raises an exception, the changes are rolled back.
completes successfully, its effects can still be rolled back if an
exception is raised in the outer block at a later point.
``atomic`` can be nested. In this case, when an inner block completes
successfully, its effects can still be rolled back if an exception is
raised in the outer block at a later point.
``atomic`` takes a ``using`` argument which should be the name of a
database. If this argument isn't provided, Django uses the ``"default"``
database.
``atomic`` is usable both as a `decorator`_::
``atomic`` is usable both as a `decorator`_::
...
@@ -137,24 +133,32 @@ Django provides a single API to control database transactions.
...
@@ -137,24 +133,32 @@ Django provides a single API to control database transactions.
@transaction.atomic
@transaction.atomic
def viewfunc(request):
def viewfunc(request):
do_stuff
()
create_parent
()
try:
try:
with transaction.atomic():
with transaction.atomic():
do_stuff_that_could_fail
()
generate_relationships
()
except IntegrityError:
except IntegrityError:
handle_exception()
handle_exception()
do_more_stuff
()
add_children
()
In this example, even if ``
do_stuff_that_could_fail
()`` causes a database
In this example, even if ``
generate_relationships
()`` causes a database
error by breaking an integrity constraint, you can execute queries in
error by breaking an integrity constraint, you can execute queries in
``do_more_stuff()``, and the changes from ``do_stuff()`` are still there.
``add_children()``, and the changes from ``create_parent()`` are still
there. Note that any operations attempted in ``generate_relationships()``
will already have been rolled back safely when ``handle_exception()`` is
called, so the exception handler can also operate on the database if
necessary.
In order to guarantee atomicity, ``atomic`` disables some APIs. Attempting
In order to guarantee atomicity, ``atomic`` disables some APIs. Attempting
to commit, roll back, or change the autocommit state of the database
to commit, roll back, or change the autocommit state of the database
connection within an ``atomic`` block will raise an exception.
connection within an ``atomic`` block will raise an exception.
``atomic`` takes a ``using`` argument which should be the name of a
database. If this argument isn't provided, Django uses the ``"default"``
database.
Under the hood, Django's transaction management code:
Under the hood, Django's transaction management code:
- opens a transaction when entering the outermost ``atomic`` block;
- opens a transaction when entering the outermost ``atomic`` block;
...
@@ -516,7 +520,7 @@ Transaction states
...
@@ -516,7 +520,7 @@ Transaction states
The three functions described above relied on a concept called "transaction
The three functions described above relied on a concept called "transaction
states". This mechanisme was deprecated in Django 1.6, but it's still
states". This mechanisme was deprecated in Django 1.6, but it's still
available until Django 1.8.
.
available until Django 1.8.
At any time, each database connection is in one of these two states:
At any time, each database connection is in one of these two states:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment