From c969b17ad83e8efdd7f887b61ad75370395434ca Mon Sep 17 00:00:00 2001 From: Akshesh Date: Sun, 14 Aug 2016 05:30:51 +0530 Subject: [PATCH] Refs #26709 -- Added type check for models.Index fields argument. --- django/db/models/indexes.py | 2 ++ tests/model_indexes/tests.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/django/db/models/indexes.py b/django/db/models/indexes.py index f70c2e5625..2396ba2819 100644 --- a/django/db/models/indexes.py +++ b/django/db/models/indexes.py @@ -14,6 +14,8 @@ class Index(object): suffix = 'idx' def __init__(self, fields=[], name=None): + if not isinstance(fields, list): + raise ValueError('Index.fields must be a list.') if not fields: raise ValueError('At least one field is required to define an index.') self.fields = fields diff --git a/tests/model_indexes/tests.py b/tests/model_indexes/tests.py index 52db494905..0e276dbd15 100644 --- a/tests/model_indexes/tests.py +++ b/tests/model_indexes/tests.py @@ -22,6 +22,10 @@ class IndexesTests(TestCase): self.assertEqual(index, same_index) self.assertNotEqual(index, another_index) + def test_index_fields_type(self): + with self.assertRaisesMessage(ValueError, 'Index.fields must be a list.'): + models.Index(fields='title') + def test_raises_error_without_field(self): msg = 'At least one field is required to define an index.' with self.assertRaisesMessage(ValueError, msg):