Code

Opened 19 months ago

Closed 19 months ago

Last modified 19 months ago

#19416 closed Bug (fixed)

Multi-line statements broken in custom SQL

Reported by: aaugustin Owned by: claudep
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 claudep 19 months ago.

Download all attachments as: .zip

Change History (4)

comment:1 Changed 19 months ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to claudep
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Changed 19 months ago by claudep

comment:2 Changed 19 months ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 5fa5621f574f9ae211ed756c3e2ad453470dae8a:

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

Thanks Aymeric Augustin for detecting this regression.

comment:3 Changed 19 months ago by Claude Paroz <claude@…>

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.