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
f6f188ff
Kaydet (Commit)
f6f188ff
authored
Nis 09, 2014
tarafından
Aymeric Augustin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
[1.7.x] Fixed #21553 -- Ensured unusable database connections get closed.
Backport of
5f2f47fd
from master
üst
396d65b5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
4 deletions
+40
-4
__init__.py
django/db/backends/__init__.py
+6
-1
base.py
django/db/backends/mysql/base.py
+1
-1
base.py
django/db/backends/oracle/base.py
+1
-1
base.py
django/db/backends/postgresql_psycopg2/base.py
+1
-1
tests.py
tests/backends/tests.py
+31
-0
No files found.
django/db/backends/__init__.py
Dosyayı görüntüle @
f6f188ff
...
...
@@ -445,9 +445,14 @@ class BaseDatabaseWrapper(object):
def
is_usable
(
self
):
"""
Tests if the database connection is usable.
This function may assume that self.connection is not None.
Actual implementations should take care not to raise exceptions
as that may prevent Django from recycling unusable connections.
"""
raise
NotImplementedError
(
'subclasses of BaseDatabaseWrapper may require an is_usable() method'
)
raise
NotImplementedError
(
"subclasses of BaseDatabaseWrapper may require an is_usable() method"
)
def
close_if_unusable_or_obsolete
(
self
):
"""
...
...
django/db/backends/mysql/base.py
Dosyayı görüntüle @
f6f188ff
...
...
@@ -552,7 +552,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
def
is_usable
(
self
):
try
:
self
.
connection
.
ping
()
except
DatabaseError
:
except
Database
.
Error
:
return
False
else
:
return
True
...
...
django/db/backends/oracle/base.py
Dosyayı görüntüle @
f6f188ff
...
...
@@ -704,7 +704,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
else
:
# Use a cx_Oracle cursor directly, bypassing Django's utilities.
self
.
connection
.
cursor
()
.
execute
(
"SELECT 1 FROM DUAL"
)
except
DatabaseError
:
except
Database
.
Error
:
return
False
else
:
return
True
...
...
django/db/backends/postgresql_psycopg2/base.py
Dosyayı görüntüle @
f6f188ff
...
...
@@ -213,7 +213,7 @@ class DatabaseWrapper(BaseDatabaseWrapper):
try
:
# Use a psycopg cursor directly, bypassing Django's utilities.
self
.
connection
.
cursor
()
.
execute
(
"SELECT 1"
)
except
DatabaseError
:
except
Database
.
Error
:
return
False
else
:
return
True
...
...
tests/backends/tests.py
Dosyayı görüntüle @
f6f188ff
...
...
@@ -664,6 +664,37 @@ class BackendTestCase(TestCase):
self
.
assertTrue
(
cursor
.
closed
)
class
IsUsableTests
(
TransactionTestCase
):
# Avoid using a regular TestCase because Django really dislikes closing
# the database connection inside a transaction at this point (#21202).
available_apps
=
[]
# Unfortunately with sqlite3 the in-memory test database cannot be closed.
@skipUnlessDBFeature
(
'test_db_allows_multiple_connections'
)
def
test_is_usable_after_database_disconnects
(
self
):
"""
Test that is_usable() doesn't crash when the database disconnects.
Regression for #21553.
"""
# Open a connection to the database.
with
connection
.
cursor
():
pass
# Emulate a connection close by the database.
connection
.
_close
()
# Even then is_usable() should not raise an exception.
try
:
self
.
assertFalse
(
connection
.
is_usable
())
finally
:
# Clean up the mess created by connection._close(). Since the
# connection is already closed, this crashes on some backends.
try
:
connection
.
close
()
except
Exception
:
pass
# We don't make these tests conditional because that means we would need to
# check and differentiate between:
# * MySQL+InnoDB, MySQL+MYISAM (something we currently can't do).
...
...
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