From 65e321b78161d83db408504290edbfbace267233 Mon Sep 17 00:00:00 2001 From: Mads Jensen Date: Mon, 16 Jan 2017 17:28:30 +0100 Subject: [PATCH] Refs #25809 -- Made a few late review comments for BrinIndex. --- django/contrib/postgres/indexes.py | 6 +++--- django/db/models/indexes.py | 4 ++-- docs/ref/contrib/postgres/indexes.txt | 8 ++++---- tests/postgres_tests/test_indexes.py | 7 ++----- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/django/contrib/postgres/indexes.py b/django/contrib/postgres/indexes.py index 897fbc1f57..185ea7435c 100644 --- a/django/contrib/postgres/indexes.py +++ b/django/contrib/postgres/indexes.py @@ -9,10 +9,10 @@ class BrinIndex(Index): suffix = 'brin' def __init__(self, fields=[], name=None, pages_per_range=None): - if pages_per_range is not None and not (isinstance(pages_per_range, int) and pages_per_range > 0): - raise ValueError('pages_per_range must be None or a positive integer for BRIN indexes') + if pages_per_range is not None and pages_per_range <= 0: + raise ValueError('pages_per_range must be None or a positive integer') self.pages_per_range = pages_per_range - return super(BrinIndex, self).__init__(fields, name) + super(BrinIndex, self).__init__(fields, name) def __repr__(self): if self.pages_per_range is not None: diff --git a/django/db/models/indexes.py b/django/db/models/indexes.py index 35f84f37de..5922131292 100644 --- a/django/db/models/indexes.py +++ b/django/db/models/indexes.py @@ -60,9 +60,9 @@ class Index(object): 'extra': tablespace_sql, } - def create_sql(self, model, schema_editor, using='', parameters=None): + def create_sql(self, model, schema_editor, using=''): sql_create_index = schema_editor.sql_create_index - sql_parameters = parameters or self.get_sql_create_template_values(model, schema_editor, using) + sql_parameters = self.get_sql_create_template_values(model, schema_editor, using) return sql_create_index % sql_parameters def remove_sql(self, model, schema_editor): diff --git a/docs/ref/contrib/postgres/indexes.txt b/docs/ref/contrib/postgres/indexes.txt index 0995d1b75e..ce5a50caf3 100644 --- a/docs/ref/contrib/postgres/indexes.txt +++ b/docs/ref/contrib/postgres/indexes.txt @@ -12,12 +12,12 @@ available from the ``django.contrib.postgres.indexes`` module. ``BrinIndex`` ============= -.. class:: BrinIndex(pages_per_range=None) +.. class:: BrinIndex(fields=[], name=None, pages_per_range=None) Creates a `BRIN index - `_. For - performance considerations and use cases of the index, please consult the - documentation. + `_. + + The ``pages_per_range`` argument takes a positive integer. ``GinIndex`` ============ diff --git a/tests/postgres_tests/test_indexes.py b/tests/postgres_tests/test_indexes.py index 48b08a2737..9298b86e73 100644 --- a/tests/postgres_tests/test_indexes.py +++ b/tests/postgres_tests/test_indexes.py @@ -27,7 +27,7 @@ class BrinIndexTests(PostgreSQLTestCase): self.assertEqual(args, ()) self.assertEqual(kwargs, {'fields': ['title'], 'name': 'test_title_brin', 'pages_per_range': None}) - def test_deconstruction_with_pages_per_rank(self): + def test_deconstruction_with_pages_per_range(self): index = BrinIndex(fields=['title'], name='test_title_brin', pages_per_range=16) path, args, kwargs = index.deconstruct() self.assertEqual(path, 'django.contrib.postgres.indexes.BrinIndex') @@ -35,10 +35,7 @@ class BrinIndexTests(PostgreSQLTestCase): self.assertEqual(kwargs, {'fields': ['title'], 'name': 'test_title_brin', 'pages_per_range': 16}) def test_invalid_pages_per_range(self): - with self.assertRaises(ValueError): - BrinIndex(fields=['title'], name='test_title_brin', pages_per_range='Charles Babbage') - - with self.assertRaises(ValueError): + with self.assertRaisesMessage(ValueError, 'pages_per_range must be None or a positive integer'): BrinIndex(fields=['title'], name='test_title_brin', pages_per_range=0)