From 743d28f5539b17d6e39bd37c6e3df5628b470cac Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Tue, 5 Dec 2017 09:19:52 +0000 Subject: [PATCH] Refs #27869 -- Added PostgreSQL version check for GinIndex support. --- django/contrib/postgres/indexes.py | 4 ++++ tests/postgres_tests/test_indexes.py | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/django/contrib/postgres/indexes.py b/django/contrib/postgres/indexes.py index 1850b209786..f8014f87a01 100644 --- a/django/contrib/postgres/indexes.py +++ b/django/contrib/postgres/indexes.py @@ -105,6 +105,10 @@ class GinIndex(PostgresIndex): kwargs['gin_pending_list_limit'] = self.gin_pending_list_limit return path, args, kwargs + def check_supported(self, schema_editor): + if self.gin_pending_list_limit and not schema_editor.connection.features.has_gin_pending_list_limit: + raise NotSupportedError('GIN option gin_pending_list_limit requires PostgreSQL 9.5+.') + def get_with_params(self): with_params = [] if self.gin_pending_list_limit is not None: diff --git a/tests/postgres_tests/test_indexes.py b/tests/postgres_tests/test_indexes.py index f4ac359a3ac..b9820aa362c 100644 --- a/tests/postgres_tests/test_indexes.py +++ b/tests/postgres_tests/test_indexes.py @@ -185,6 +185,16 @@ class SchemaTests(PostgreSQLTestCase): editor.remove_index(IntegerArrayModel, index) self.assertNotIn(index_name, self.get_constraints(IntegerArrayModel._meta.db_table)) + 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) + self.assertNotIn(index_name, self.get_constraints(IntegerArrayModel._meta.db_table)) + @skipUnlessDBFeature('has_brin_index_support') def test_brin_index(self): index_name = 'char_field_model_field_brin'