Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #2161 -- handle trailing newlines in initial SQL data. Includes

regression test. Thanks to russellm.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3177 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 3e97535907baa7b57c9bf322871ef6243e2045a9 1 parent a513fcb
Malcolm Tredinnick malcolmt authored
5 django/core/management.py
View
@@ -334,8 +334,9 @@ def get_sql_initial_data_for_model(model):
# Some backends can't execute more than one SQL statement at a time,
# so split into separate statements.
sql_expr = re.compile(
- r"""( # each statement is...
- (?: # one or more chunks of ...
+ r"""( # each statement ...
+ [^\r\n;] # starts with something other than a line ending or ';'
+ (?: # then has one or more chunks of ...
(?:[^;'"]+) # not the end of a statement or start of a quote
| (?:'[^']*') # something in single quotes
| (?:"[^"]*") # something in double quotes
0  tests/regressiontests/initial_sql_regress/__init__.py
View
No changes.
13 tests/regressiontests/initial_sql_regress/models.py
View
@@ -0,0 +1,13 @@
+"""
+Regression tests for initial SQL insertion.
+"""
+
+from django.db import models
+
+class Simple(models.Model):
+ name = models.CharField(maxlength = 50)
+
+API_TESTS = ""
+
+# NOTE: The format of the included SQL file for this test suite is important.
+# It must end with a trailing newline in order to test the fix for #2161.
5 tests/regressiontests/initial_sql_regress/sql/simple.sql
View
@@ -0,0 +1,5 @@
+INSERT INTO initial_sql_regress_simple (name) VALUES ('John');
+INSERT INTO initial_sql_regress_simple (name) VALUES ('Paul');
+INSERT INTO initial_sql_regress_simple (name) VALUES ('Ringo');
+INSERT INTO initial_sql_regress_simple (name) VALUES ('George');
+
9 tests/runtests.py
View
@@ -34,8 +34,13 @@ def log_error(model_name, title, description):
]
def get_test_models():
- return [(MODEL_TESTS_DIR_NAME, f) for f in os.listdir(MODEL_TEST_DIR) if not f.startswith('__init__') and not f.startswith('.')] +\
- [(REGRESSION_TESTS_DIR_NAME, f) for f in os.listdir(REGRESSION_TEST_DIR) if not f.startswith('__init__') and not f.startswith('.')]
+ models = []
+ for loc in MODEL_TESTS_DIR_NAME, REGRESSION_TESTS_DIR_NAME:
+ for f in os.listdir(loc):
+ if f.startswith('__init__') or f.startswith('.') or f.startswith('sql'):
+ continue
+ models.append((loc, f))
+ return models
class DjangoDoctestRunner(doctest.DocTestRunner):
def __init__(self, verbosity_level, *args, **kwargs):
Please sign in to comment.
Something went wrong with that request. Please try again.