Commit 3e975359 authored by Malcolm Tredinnick's avatar Malcolm Tredinnick
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
parent a513fcb4
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -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 −0

Empty file added.

+13 −0
Original line number Diff line number Diff line
"""
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 −0
Original line number Diff line number Diff line
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');
+7 −2
Original line number Diff line number Diff line
@@ -34,8 +34,13 @@ ALWAYS_INSTALLED_APPS = [
]

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):