#23909 closed Bug (fixed)
RunSQL calls execute with params None, params used in map
| Reported by: | James Rivett-Carnac | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 1.7 |
| Severity: | Release blocker | Keywords: | migrations |
| Cc: | Triage Stage: | Accepted | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
with a migration operation:
migrations.RunSQL(
"""CREATE TABLE ...; CREATE TABLE...; """,
"""DROP TABLE ...; DROP TABLE...;"""",
state_operations=[list of the equivalent migrations])
calling migrate on this gives me a TypeError on line in django.db.backends.schema.execute():96
self.collected_sql.append((sql % tuple(map(self.quote_value, params))) + ';')
But this is being called by django.db.migrations.operations.special:69
schema_editor.execute(statement, params=None)
This will always fail if it is called so - None never being itterable. the method signature for django.db.backends.schema.execute(sql, params=[]) should be enough rather than calling with None.
Change History (6)
comment:1 by , 11 years ago
| Severity: | Normal → Release blocker |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 11 years ago
Depending on your database backend (SQLite and MySQL for sure; not sure about Oracle) you need to have sqlparse installed.
A related problem was tackled in #23426. Django 1.8 will add extended support for multiple statements including parameters.
I'd close the ticket as "invalid" or "needsinfo", because I'm not sure which backend you are using.
comment:3 by , 11 years ago
To reproduce the error in current tests:
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index 32f70e8..08a5600 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -1292,7 +1292,7 @@ class OperationTests(OperationTestBase):
# Make sure there's no table
self.assertTableNotExists("i_love_ponies")
# Test the database alteration
- with connection.schema_editor() as editor:
+ with connection.schema_editor(collect_sql=True) as editor:
operation.database_forwards("test_runsql", editor, project_state, new_state)
self.assertTableExists("i_love_ponies")
# Make sure all the SQL was processed
comment:5 by , 11 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
It's important to be able to keep
params=Noneas it will have an impact on the parameter substitution in the sql string. Therefore I think that it's theself.collected_sql.appendline that has to be fixed to take theNonevalue into account.