diff --git a/django/db/backends/mysql/features.py b/django/db/backends/mysql/features.py index 4cc9bbae37..21e2e04181 100644 --- a/django/db/backends/mysql/features.py +++ b/django/db/backends/mysql/features.py @@ -1,3 +1,5 @@ +import operator + from django.db.backends.base.features import BaseDatabaseFeatures from django.utils.functional import cached_property @@ -91,7 +93,7 @@ class DatabaseFeatures(BaseDatabaseFeatures): def has_select_for_update_skip_locked(self): return not self.connection.mysql_is_mariadb and self.connection.mysql_version >= (8, 0, 1) - has_select_for_update_nowait = has_select_for_update_skip_locked + has_select_for_update_nowait = property(operator.attrgetter('has_select_for_update_skip_locked')) @cached_property def needs_explain_extended(self): diff --git a/django/db/backends/postgresql/features.py b/django/db/backends/postgresql/features.py index 4fae7b1d34..3f43abf9d5 100644 --- a/django/db/backends/postgresql/features.py +++ b/django/db/backends/postgresql/features.py @@ -1,3 +1,5 @@ +import operator + from django.db.backends.base.features import BaseDatabaseFeatures from django.db.utils import InterfaceError from django.utils.functional import cached_property @@ -64,10 +66,10 @@ class DatabaseFeatures(BaseDatabaseFeatures): def is_postgresql_10(self): return self.connection.pg_version >= 100000 - has_select_for_update_skip_locked = is_postgresql_9_5 - has_brin_index_support = is_postgresql_9_5 - has_jsonb_agg = is_postgresql_9_5 - has_brin_autosummarize = is_postgresql_10 - has_gin_pending_list_limit = is_postgresql_9_5 - supports_ignore_conflicts = is_postgresql_9_5 - has_phraseto_tsquery = is_postgresql_9_6 + has_select_for_update_skip_locked = property(operator.attrgetter('is_postgresql_9_5')) + has_brin_index_support = property(operator.attrgetter('is_postgresql_9_5')) + has_jsonb_agg = property(operator.attrgetter('is_postgresql_9_5')) + has_brin_autosummarize = property(operator.attrgetter('is_postgresql_10')) + has_gin_pending_list_limit = property(operator.attrgetter('is_postgresql_9_5')) + supports_ignore_conflicts = property(operator.attrgetter('is_postgresql_9_5')) + has_phraseto_tsquery = property(operator.attrgetter('is_postgresql_9_6')) diff --git a/tests/postgres_tests/test_indexes.py b/tests/postgres_tests/test_indexes.py index 96ab423da7..d692b6662a 100644 --- a/tests/postgres_tests/test_indexes.py +++ b/tests/postgres_tests/test_indexes.py @@ -219,14 +219,14 @@ class SchemaTests(PostgreSQLTestCase): editor.remove_index(IntegerArrayModel, index) self.assertNotIn(index_name, self.get_constraints(IntegerArrayModel._meta.db_table)) + @mock.patch('django.db.backends.postgresql.features.DatabaseFeatures.has_gin_pending_list_limit', False) def test_gin_parameters_exception(self): index_name = 'gin_options_exception' index = GinIndex(fields=['field'], name=index_name, gin_pending_list_limit=64) msg = 'GIN option gin_pending_list_limit requires PostgreSQL 9.5+.' with self.assertRaisesMessage(NotSupportedError, msg): - with mock.patch('django.db.connection.features.has_gin_pending_list_limit', False): - with connection.schema_editor() as editor: - editor.add_index(IntegerArrayModel, index) + with connection.schema_editor() as editor: + editor.add_index(IntegerArrayModel, index) self.assertNotIn(index_name, self.get_constraints(IntegerArrayModel._meta.db_table)) @skipUnlessDBFeature('has_brin_index_support') @@ -259,7 +259,7 @@ class SchemaTests(PostgreSQLTestCase): index_name = 'brin_index_exception' index = BrinIndex(fields=['field'], name=index_name) with self.assertRaisesMessage(NotSupportedError, 'BRIN indexes require PostgreSQL 9.5+.'): - with mock.patch('django.db.connection.features.has_brin_index_support', False): + with mock.patch('django.db.backends.postgresql.features.DatabaseFeatures.has_brin_index_support', False): with connection.schema_editor() as editor: editor.add_index(CharFieldModel, index) self.assertNotIn(index_name, self.get_constraints(CharFieldModel._meta.db_table)) @@ -269,7 +269,7 @@ class SchemaTests(PostgreSQLTestCase): index_name = 'brin_options_exception' index = BrinIndex(fields=['field'], name=index_name, autosummarize=True) with self.assertRaisesMessage(NotSupportedError, 'BRIN option autosummarize requires PostgreSQL 10+.'): - with mock.patch('django.db.connection.features.has_brin_autosummarize', False): + with mock.patch('django.db.backends.postgresql.features.DatabaseFeatures.has_brin_autosummarize', False): with connection.schema_editor() as editor: editor.add_index(CharFieldModel, index) self.assertNotIn(index_name, self.get_constraints(CharFieldModel._meta.db_table))