From 7f4fc5cbd4c26e137a1abdd9bd603804ddc0e769 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 23 Feb 2022 11:41:37 -0800 Subject: [PATCH] Fixed #33539 -- Fixed spaces in WITH SQL for indexes on PostgreSQL. --- django/contrib/postgres/indexes.py | 2 +- tests/postgres_tests/test_indexes.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/django/contrib/postgres/indexes.py b/django/contrib/postgres/indexes.py index 409f5141473..a0c03681b21 100644 --- a/django/contrib/postgres/indexes.py +++ b/django/contrib/postgres/indexes.py @@ -29,7 +29,7 @@ class PostgresIndex(Index): ) with_params = self.get_with_params() if with_params: - statement.parts["extra"] = "WITH (%s) %s" % ( + statement.parts["extra"] = " WITH (%s)%s" % ( ", ".join(with_params), statement.parts["extra"], ) diff --git a/tests/postgres_tests/test_indexes.py b/tests/postgres_tests/test_indexes.py index 100e570092a..2f74203e8ba 100644 --- a/tests/postgres_tests/test_indexes.py +++ b/tests/postgres_tests/test_indexes.py @@ -330,9 +330,14 @@ class SchemaTests(PostgreSQLTestCase): name=index_name, fastupdate=True, gin_pending_list_limit=64, + db_tablespace="pg_default", ) with connection.schema_editor() as editor: editor.add_index(IntegerArrayModel, index) + self.assertIn( + ") WITH (gin_pending_list_limit = 64, fastupdate = on) TABLESPACE", + str(index.create_sql(IntegerArrayModel, editor)), + ) constraints = self.get_constraints(IntegerArrayModel._meta.db_table) self.assertEqual(constraints[index_name]["type"], "gin") self.assertEqual(