From 3e52fd7595f80ec162fc44798c29399b7e899b9b Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Tue, 5 Dec 2017 21:05:10 +0100 Subject: [1.11.x] Refs #28876 -- Fixed incorrect class-based model index name generation for models with quoted db_table. Thanks Simon Charette and Tim Graham for the review and Carlos E. C. Leite for the report. Backport of f79d9a322c6008e5fada1453aebfb56afc316cc8 from master --- tests/model_indexes/tests.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests') diff --git a/tests/model_indexes/tests.py b/tests/model_indexes/tests.py index 74c7cf45f4..d3815eee0d 100644 --- a/tests/model_indexes/tests.py +++ b/tests/model_indexes/tests.py @@ -1,5 +1,6 @@ from django.db import models from django.test import SimpleTestCase +from django.test.utils import isolate_apps from .models import Book, ChildModel1, ChildModel2 @@ -69,6 +70,18 @@ class IndexesTests(SimpleTestCase): with self.assertRaisesMessage(AssertionError, msg): long_field_index.set_name_with_model(Book) + @isolate_apps('model_indexes') + def test_name_auto_generation_with_quoted_db_table(self): + class QuotedDbTable(models.Model): + name = models.CharField(max_length=50) + + class Meta: + db_table = '"t_quoted"' + + index = models.Index(fields=['name']) + index.set_name_with_model(QuotedDbTable) + self.assertEqual(index.name, 't_quoted_name_e4ed1b_idx') + def test_deconstruction(self): index = models.Index(fields=['title']) index.set_name_with_model(Book) -- cgit v1.3