Fixed #29380 -- Added support for QuerySet.select_for_update()'s nowait and skip_locked options on MySQL 8+.
This commit is contained in:
parent
e038f98bf3
commit
a7bc1aea03
1
AUTHORS
1
AUTHORS
|
@ -21,6 +21,7 @@ answer newbie questions, and generally made Django that much better:
|
||||||
AgarFu <heaven@croasanaso.sytes.net>
|
AgarFu <heaven@croasanaso.sytes.net>
|
||||||
Ahmad Alhashemi <trans@ahmadh.com>
|
Ahmad Alhashemi <trans@ahmadh.com>
|
||||||
Ahmad Al-Ibrahim
|
Ahmad Al-Ibrahim
|
||||||
|
Ahmed Eltawela <https://github.com/ahmedabt>
|
||||||
ajs <adi@sieker.info>
|
ajs <adi@sieker.info>
|
||||||
Akis Kesoglou <akiskesoglou@gmail.com>
|
Akis Kesoglou <akiskesoglou@gmail.com>
|
||||||
Aksel Ethem <aksel.ethem@gmail.com>
|
Aksel Ethem <aksel.ethem@gmail.com>
|
||||||
|
|
|
@ -10,7 +10,6 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
||||||
# MySQL doesn't support sliced subqueries with IN/ALL/ANY/SOME.
|
# MySQL doesn't support sliced subqueries with IN/ALL/ANY/SOME.
|
||||||
allow_sliced_subqueries_with_in = False
|
allow_sliced_subqueries_with_in = False
|
||||||
has_select_for_update = True
|
has_select_for_update = True
|
||||||
has_select_for_update_nowait = False
|
|
||||||
supports_forward_references = False
|
supports_forward_references = False
|
||||||
supports_regex_backreferencing = False
|
supports_regex_backreferencing = False
|
||||||
supports_date_lookup_using_string = False
|
supports_date_lookup_using_string = False
|
||||||
|
@ -83,6 +82,12 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
||||||
def supports_over_clause(self):
|
def supports_over_clause(self):
|
||||||
return self.connection.mysql_version >= (8, 0, 2)
|
return self.connection.mysql_version >= (8, 0, 2)
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def has_select_for_update_skip_locked(self):
|
||||||
|
return self.connection.mysql_version >= (8, 0, 1)
|
||||||
|
|
||||||
|
has_select_for_update_nowait = has_select_for_update_skip_locked
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def needs_explain_extended(self):
|
def needs_explain_extended(self):
|
||||||
# EXTENDED is deprecated (and not required) in 5.7 and removed in 8.0.
|
# EXTENDED is deprecated (and not required) in 5.7 and removed in 8.0.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
from unittest import mock, skipUnless
|
from unittest import mock, skipUnless
|
||||||
|
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
|
from django.db.backends.mysql.features import DatabaseFeatures
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,3 +18,15 @@ class TestFeatures(TestCase):
|
||||||
with mock.patch('django.db.connection.features._mysql_storage_engine', 'MyISAM'):
|
with mock.patch('django.db.connection.features._mysql_storage_engine', 'MyISAM'):
|
||||||
self.assertFalse(connection.features.supports_transactions)
|
self.assertFalse(connection.features.supports_transactions)
|
||||||
del connection.features.supports_transactions
|
del connection.features.supports_transactions
|
||||||
|
|
||||||
|
def test_skip_locked_no_wait(self):
|
||||||
|
with mock.MagicMock() as _connection:
|
||||||
|
_connection.mysql_version = (8, 0, 1)
|
||||||
|
database_features = DatabaseFeatures(_connection)
|
||||||
|
self.assertTrue(database_features.has_select_for_update_skip_locked)
|
||||||
|
self.assertTrue(database_features.has_select_for_update_nowait)
|
||||||
|
with mock.MagicMock() as _connection:
|
||||||
|
_connection.mysql_version = (8, 0, 0)
|
||||||
|
database_features = DatabaseFeatures(_connection)
|
||||||
|
self.assertFalse(database_features.has_select_for_update_skip_locked)
|
||||||
|
self.assertFalse(database_features.has_select_for_update_nowait)
|
||||||
|
|
Loading…
Reference in New Issue