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
58161e4e
Kaydet (Commit)
58161e4e
authored
Mar 23, 2014
tarafından
Aymeric Augustin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #22291 -- Avoided shadowing deadlock exceptions on MySQL.
Thanks err for the report.
üst
a6fc1859
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
2 deletions
+53
-2
transaction.py
django/db/transaction.py
+7
-1
tests.py
tests/transactions/tests.py
+46
-1
No files found.
django/db/transaction.py
Dosyayı görüntüle @
58161e4e
...
...
@@ -231,7 +231,13 @@ class Atomic(object):
if
sid
is
None
:
connection
.
needs_rollback
=
True
else
:
connection
.
savepoint_rollback
(
sid
)
try
:
connection
.
savepoint_rollback
(
sid
)
except
DatabaseError
:
# If rolling back to a savepoint fails, mark for
# rollback at a higher level and avoid shadowing
# the original exception.
connection
.
needs_rollback
=
True
else
:
# Roll back transaction
connection
.
rollback
()
...
...
tests/transactions/tests.py
Dosyayı görüntüle @
58161e4e
from
__future__
import
unicode_literals
import
sys
try
:
import
threading
except
ImportError
:
threading
=
None
import
time
from
unittest
import
skipIf
,
skipUnless
from
django.db
import
connection
,
transaction
,
DatabaseError
,
IntegrityError
from
django.db
import
(
connection
,
transaction
,
DatabaseError
,
IntegrityError
,
OperationalError
)
from
django.test
import
TransactionTestCase
,
skipIfDBFeature
from
django.utils
import
six
...
...
@@ -333,6 +339,45 @@ class AtomicErrorsTests(TransactionTestCase):
self
.
assertEqual
(
Reporter
.
objects
.
get
(
pk
=
r1
.
pk
)
.
last_name
,
"Calculus"
)
@skipUnless
(
connection
.
vendor
==
'mysql'
,
"MySQL-specific behaviors"
)
class
AtomicMySQLTests
(
TransactionTestCase
):
available_apps
=
[
'transactions'
]
@skipIf
(
threading
is
None
,
"Test requires threading"
)
def
test_implicit_savepoint_rollback
(
self
):
"""MySQL implicitly rolls back savepoints when it deadlocks (#22291)."""
other_thread_ready
=
threading
.
Event
()
def
other_thread
():
try
:
with
transaction
.
atomic
():
Reporter
.
objects
.
create
(
id
=
1
,
first_name
=
"Tintin"
)
other_thread_ready
.
set
()
# We cannot synchronize the two threads with an event here
# because the main thread locks. Sleep for a little while.
time
.
sleep
(
1
)
# 2) ... and this line deadlocks. (see below for 1)
Reporter
.
objects
.
exclude
(
id
=
1
)
.
update
(
id
=
2
)
finally
:
# This is the thread-local connection, not the main connection.
connection
.
close
()
other_thread
=
threading
.
Thread
(
target
=
other_thread
)
other_thread
.
start
()
other_thread_ready
.
wait
()
with
six
.
assertRaisesRegex
(
self
,
OperationalError
,
'Deadlock found'
):
# Double atomic to enter a transaction and create a savepoint.
with
transaction
.
atomic
():
with
transaction
.
atomic
():
# 1) This line locks... (see above for 2)
Reporter
.
objects
.
create
(
id
=
1
,
first_name
=
"Tintin"
)
other_thread
.
join
()
class
AtomicMiscTests
(
TransactionTestCase
):
available_apps
=
[]
...
...
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