Multi-line statements broken in custom SQL
|Reported by:||aaugustin||Owned by:||claudep|
|Component:||Database layer (models, ORM)||Version:||1.5-beta-1|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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;']
Change History (4)
comment:1 Changed 2 years 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 2 years ago by claudep
comment:2 Changed 2 years ago by Claude Paroz <claude@…>
- Resolution set to fixed
- Status changed from new to closed