From a18e43c5bb8cb7c82c84ca1b42d847a62ac9f077 Mon Sep 17 00:00:00 2001 From: Anssi Kääriäinen Date: Mon, 30 Apr 2012 14:05:30 +0300 Subject: Made get_indexes() consistent across backends. Fixed #15933, #18082 -- the get_indexes() method introspection was done inconsitently depending on the backend. For example SQLite included all the columns in the table in the returned dictionary, while MySQL introspected also multicolumn indexes. All backends return now consistenly only single-column indexes. Thanks to andi for the MySQL report, and ikelly for comments on Oracle's get_indexes() changes. --- tests/regressiontests/introspection/models.py | 5 ++++- tests/regressiontests/introspection/tests.py | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/regressiontests/introspection/models.py b/tests/regressiontests/introspection/models.py index 3b8383e601..02a8d71549 100644 --- a/tests/regressiontests/introspection/models.py +++ b/tests/regressiontests/introspection/models.py @@ -7,6 +7,9 @@ class Reporter(models.Model): email = models.EmailField() facebook_user_id = models.BigIntegerField(null=True) + class Meta: + unique_together = ('first_name', 'last_name') + def __unicode__(self): return u"%s %s" % (self.first_name, self.last_name) @@ -19,4 +22,4 @@ class Article(models.Model): return self.headline class Meta: - ordering = ('headline',) \ No newline at end of file + ordering = ('headline',) diff --git a/tests/regressiontests/introspection/tests.py b/tests/regressiontests/introspection/tests.py index b425b6401d..ca58f04494 100644 --- a/tests/regressiontests/introspection/tests.py +++ b/tests/regressiontests/introspection/tests.py @@ -137,6 +137,15 @@ class IntrospectionTests(TestCase): indexes = connection.introspection.get_indexes(cursor, Article._meta.db_table) self.assertEqual(indexes['reporter_id'], {'unique': False, 'primary_key': False}) + def test_get_indexes_multicol(self): + """ + Test that multicolumn indexes are not included in the introspection + results. + """ + cursor = connection.cursor() + indexes = connection.introspection.get_indexes(cursor, Reporter._meta.db_table) + self.assertNotIn('first_name', indexes) + self.assertIn('id', indexes) def datatype(dbtype, description): """Helper to convert a data type into a string.""" -- cgit v1.3