Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#19416 closed Bug (fixed)

Multi-line statements broken in custom SQL

Reported by: Aymeric Augustin Owned by: Claude Paroz
Component: Database layer (models, ORM) Version: 1.5-beta-1
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

After upgrading to Django 1.5 alpha, custom SQL files containing multi-line statements aren't loaded any longer.

I get the following error:

Failed to install custom SQL for sessions.Session model: syntax error at or near "sessions_session"
LINE 1: ...E INDEX unique_active_session_user_idON sessions_s...

This regression was introduced in 423244bc6b670abc2b7d6896add5c1baf0b4ef2a.

The problem lies in the _split_statements added by this commit. It strips whitespace and joins consecutive lines without keeping a space:

>>> multi_line_sql = """
... CREATE UNIQUE INDEX unique_active_session_user_id
...     ON sessions_session(user_id)
...     WHERE closed_at IS NULL;
... """
>>> from django.core.management.sql import _split_statements
>>> _split_statements(multi_line_sql)
[u'CREATE UNIQUE INDEX unique_active_session_user_idON sessions_session(user_id)WHERE closed_at IS NULL;']

Attachments (1)

19416-1.diff (1.7 KB ) - added by Claude Paroz 12 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 by Claude Paroz, 12 years ago

Owner: changed from nobody to Claude Paroz
Triage Stage: UnreviewedAccepted

by Claude Paroz, 12 years ago

Attachment: 19416-1.diff added

comment:2 by Claude Paroz <claude@…>, 12 years ago

Resolution: fixed
Status: newclosed

In 5fa5621f574f9ae211ed756c3e2ad453470dae8a:

Fixed #19416 -- Fixed multi-line commands in initial SQL files

Thanks Aymeric Augustin for detecting this regression.

comment:3 by Claude Paroz <claude@…>, 12 years ago

In 3d62eaea692b230ddc45faa48286b356ca561218:

[1.5.x] Fixed #19416 -- Fixed multi-line commands in initial SQL files

Thanks Aymeric Augustin for detecting this regression.
Backport of 5fa5621f5 from master.

Note: See TracTickets for help on using tickets.
Back to Top