#25530: Deferred SQL operations fail when a referenced table or column is 
renamed
during the same migration
------------------------------+------------------------------------
     Reporter:  simonphilips  |                    Owner:  nobody
         Type:  Bug           |                   Status:  new
    Component:  Migrations    |                  Version:  1.8
     Severity:  Normal        |               Resolution:
     Keywords:                |             Triage Stage:  Accepted
    Has patch:  0             |      Needs documentation:  0
  Needs tests:  0             |  Patch needs improvement:  0
Easy pickings:  0             |                    UI/UX:  0
------------------------------+------------------------------------

Comment (by charettes):

 #26461 was a duplicate caused by an implicit table rename through a
 `RenameModel` operation.

 I think a possible solution would be to add state dependency tracking to
 `deferred_sql`. This way `RenameModel`, `AlterField`, `RenameField` and
 `AlterModelTable` operations could alter it to rename the references and
 `RemoveModel`, `RemoveField` operations could make sure to remove the
 unnecessary statements.

 For example, the `AddField` operation above would add a tuple of the form
 `('CREATE INDEX ...', [(ModelState('bug', 'child', [...]), 'child'),
 (ModelState('bug_parent', 'parent', [...]), 'id)]` (as it depends on both
 state and fields) and the `AlterField` operation would loop over all
 `editor.deferred_sql` and make sure to replace both the  SQL and the state
 of items depending on the model state it's about to alter. Model level
 operations (`RenameModel`, `AlterModelTable`) could simply use `None` as
 field to denote they depend on the model state itself.

 As for the SQL replacing part I think it would make more sense to
 introduce a class encapsulating the statement format string and its
 dependency than naively performing `str.replace('old_table_name',
 'new_table_name')` on the constructed SQL. This wrapper could also
 subclass `str` in order to maintain backward compatibility with the actual
 `deferred_sql`  API.

 Thoughts?

--
Ticket URL: <https://code.djangoproject.com/ticket/25530#comment:9>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/070.8830e5f134f2ae2127b4ac3e947733b8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to