summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2014-12-26 14:48:44 -0500
committerTim Graham <timograham@gmail.com>2015-01-17 10:20:30 -0500
commitb845951fd41cf6a380b3e09eeb30f7d105c37061 (patch)
tree5af8c3d8dad04c7d671d53b9dace5dcb39538176
parent4aa089a9a9504c4a833eee8161be013206da5d15 (diff)
Required sqlparse for SQL splitting per deprecation timeline.
-rw-r--r--django/core/management/sql.py18
-rw-r--r--django/db/backends/base/operations.py21
-rw-r--r--django/db/backends/postgresql_psycopg2/operations.py2
3 files changed, 7 insertions, 34 deletions
diff --git a/django/core/management/sql.py b/django/core/management/sql.py
index 2c70630ad7..f8f85a0c3d 100644
--- a/django/core/management/sql.py
+++ b/django/core/management/sql.py
@@ -1,7 +1,5 @@
from __future__ import unicode_literals
-import re
-
from django.apps import apps
from django.core.management.base import CommandError
from django.db import models, router
@@ -168,22 +166,6 @@ def sql_all(app_config, style, connection):
)
-def _split_statements(content):
- # Private API only called from code that emits a RemovedInDjango19Warning.
- comment_re = re.compile(r"^((?:'[^']*'|[^'])*?)--.*$")
- statements = []
- statement = []
- for line in content.split("\n"):
- cleaned_line = comment_re.sub(r"\1", line).strip()
- if not cleaned_line:
- continue
- statement.append(cleaned_line)
- if cleaned_line.endswith(";"):
- statements.append(" ".join(statement))
- statement = []
- return statements
-
-
def emit_pre_migrate_signal(verbosity, interactive, db):
# Emit the pre_migrate signal for every application.
for app_config in apps.get_app_configs():
diff --git a/django/db/backends/base/operations.py b/django/db/backends/base/operations.py
index 24bcbb3d08..09a6316376 100644
--- a/django/db/backends/base/operations.py
+++ b/django/db/backends/base/operations.py
@@ -1,13 +1,12 @@
import datetime
import decimal
from importlib import import_module
-import warnings
from django.conf import settings
+from django.core.exceptions import ImproperlyConfigured
from django.db.backends import utils
from django.utils import six, timezone
from django.utils.dateparse import parse_duration
-from django.utils.deprecation import RemovedInDjango19Warning
from django.utils.encoding import force_text
@@ -255,7 +254,7 @@ class BaseDatabaseOperations(object):
"""
return 'DEFAULT'
- def prepare_sql_script(self, sql, _allow_fallback=False):
+ def prepare_sql_script(self, sql):
"""
Takes a SQL script that may contain multiple lines and returns a list
of statements to feed to successive cursor.execute() calls.
@@ -264,21 +263,13 @@ class BaseDatabaseOperations(object):
cursor.execute() call and PEP 249 doesn't talk about this use case,
the default implementation is conservative.
"""
- # Remove _allow_fallback and keep only 'return ...' in Django 1.9.
try:
- # This import must stay inside the method because it's optional.
import sqlparse
except ImportError:
- if _allow_fallback:
- # Without sqlparse, fall back to the legacy (and buggy) logic.
- warnings.warn(
- "Providing initial SQL data on a %s database will require "
- "sqlparse in Django 1.9." % self.connection.vendor,
- RemovedInDjango19Warning)
- from django.core.management.sql import _split_statements
- return _split_statements(sql)
- else:
- raise
+ raise ImproperlyConfigured(
+ "sqlparse is required if you don't split your SQL "
+ "statements manually."
+ )
else:
return [sqlparse.format(statement, strip_comments=True)
for statement in sqlparse.split(sql) if statement]
diff --git a/django/db/backends/postgresql_psycopg2/operations.py b/django/db/backends/postgresql_psycopg2/operations.py
index 27b19db459..ab9f60e927 100644
--- a/django/db/backends/postgresql_psycopg2/operations.py
+++ b/django/db/backends/postgresql_psycopg2/operations.py
@@ -86,7 +86,7 @@ class DatabaseOperations(BaseDatabaseOperations):
def no_limit_value(self):
return None
- def prepare_sql_script(self, sql, _allow_fallback=False):
+ def prepare_sql_script(self, sql):
return [sql]
def quote_name(self, name):