Kaydet (Commit) 6e4e0f4c authored tarafından Mariusz Felisiak's avatar Mariusz Felisiak Kaydeden (comit) Tim Graham

Fixed #26541 -- Allowed MySQL transaction detection to work without table creation.

üst fa2f55cf
...@@ -78,3 +78,10 @@ class DatabaseFeatures(BaseDatabaseFeatures): ...@@ -78,3 +78,10 @@ class DatabaseFeatures(BaseDatabaseFeatures):
cursor.execute('SELECT @@SQL_AUTO_IS_NULL') cursor.execute('SELECT @@SQL_AUTO_IS_NULL')
result = cursor.fetchone() result = cursor.fetchone()
return result and result[0] == 1 return result and result[0] == 1
@cached_property
def supports_transactions(self):
"""
All storage engines except MyISAM support transactions.
"""
return self._mysql_storage_engine != 'MyISAM'
from unittest import skipUnless
from django.db import connection from django.db import connection
from django.test import TestCase from django.test import TestCase, mock
class TestDatabaseFeatures(TestCase): class TestDatabaseFeatures(TestCase):
def test_nonexistent_feature(self): def test_nonexistent_feature(self):
self.assertFalse(hasattr(connection.features, 'nonexistent')) self.assertFalse(hasattr(connection.features, 'nonexistent'))
@skipUnless(connection.vendor == 'mysql', 'MySQL backend tests')
class TestMySQLFeatures(TestCase):
def test_mysql_supports_transactions(self):
"""
All storage engines except MyISAM support transactions.
"""
with mock.patch('django.db.connection.features._mysql_storage_engine', 'InnoDB'):
self.assertTrue(connection.features.supports_transactions)
del connection.features.supports_transactions
with mock.patch('django.db.connection.features._mysql_storage_engine', 'MyISAM'):
self.assertFalse(connection.features.supports_transactions)
del connection.features.supports_transactions
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment