From c11219833253d42d72f4a48a6c9e3a4944c27391 Mon Sep 17 00:00:00 2001 From: Conrad Kramer Date: Mon, 25 Apr 2016 16:30:48 -0700 Subject: [PATCH] Fixed #26542 -- Fixed quoting in CreateExtension operation. --- django/contrib/postgres/operations.py | 4 ++-- tests/postgres_tests/migrations/0001_setup_extensions.py | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/django/contrib/postgres/operations.py b/django/contrib/postgres/operations.py index 3bb81dc3f9..2a0a8402ed 100644 --- a/django/contrib/postgres/operations.py +++ b/django/contrib/postgres/operations.py @@ -14,10 +14,10 @@ class CreateExtension(Operation): def database_forwards(self, app_label, schema_editor, from_state, to_state): if schema_editor.connection.vendor != 'postgresql': return - schema_editor.execute("CREATE EXTENSION IF NOT EXISTS %s" % self.name) + schema_editor.execute("CREATE EXTENSION IF NOT EXISTS %s" % schema_editor.quote_name(self.name)) def database_backwards(self, app_label, schema_editor, from_state, to_state): - schema_editor.execute("DROP EXTENSION %s" % self.name) + schema_editor.execute("DROP EXTENSION %s" % schema_editor.quote_name(self.name)) def describe(self): return "Creates extension %s" % self.name diff --git a/tests/postgres_tests/migrations/0001_setup_extensions.py b/tests/postgres_tests/migrations/0001_setup_extensions.py index ad5d1c716a..07d5bfc7e7 100644 --- a/tests/postgres_tests/migrations/0001_setup_extensions.py +++ b/tests/postgres_tests/migrations/0001_setup_extensions.py @@ -5,20 +5,21 @@ from django.db import migrations try: from django.contrib.postgres.operations import ( - HStoreExtension, UnaccentExtension, + CreateExtension, HStoreExtension, UnaccentExtension, ) except ImportError: from django.test import mock + CreateExtension = mock.Mock() HStoreExtension = mock.Mock() UnaccentExtension = mock.Mock() class Migration(migrations.Migration): - dependencies = [ - ] - operations = [ + # Ensure CreateExtension quotes extension names by creating one with a + # dash in its name. + CreateExtension('uuid-ossp'), HStoreExtension(), UnaccentExtension(), ]