Fix evolution optimization issues when renaming models.
Review Request #8085 — Created March 30, 2016 and submitted
Django Evolution's evolution optimization code had issues when applying
a series of evolutions that add aForeignKey
field to a newly-introduced
model that is then renamed in the same batch. The resulting field would
still point to the original model, resulting in aKeyError
.This was partly caused by the optimization code not attempting to update
therelated_model
attribute of the new field when merging field
attributes, and partly due to theRenameModel
mutation not being
available during the evolution process for a newly-introduced model (due
to it being filtered out earlier on).This change fixes this by adding code for tracking model renames and
deletions, ensuring theRenameModel
is always present in the
optimization steps, and making sure thatrelated_model
attribute is set
for newly-introduced fields when the specified model has been renamed.Optimizations were also added to condense model renames, and to remove
any mutations that rename models that will later be deleted.
Unit tests pass for SQLite, MySQL, and PostgreSQL.
Tested against a database that hit this particular bug. I received a
KeyError
before the fix, but after, I was able to successfully upgrade.
- Change Summary:
-
- Fixed a harmless reused variable warning by simplifying a small block of code.
- Commit:
-
e9ff42650025df6a51d773849db753075c629a338bf09d090d0617471663d2adbc8a3c4430123baa
-
Tool: Pyflakes Processed Files: django_evolution/tests/db/sqlite3.py django_evolution/tests/db/postgresql.py django_evolution/mutators.py django_evolution/tests/test_preprocessing.py django_evolution/evolve.py django_evolution/tests/db/mysql.py Tool: PEP8 Style Checker Processed Files: django_evolution/tests/db/sqlite3.py django_evolution/tests/db/postgresql.py django_evolution/mutators.py django_evolution/tests/test_preprocessing.py django_evolution/evolve.py django_evolution/tests/db/mysql.py
-
- Change Summary:
-
Fixed one more harmless warning about a reused variable name by renaming the variable.
- Commit:
-
8bf09d090d0617471663d2adbc8a3c4430123baa1f7432766b5f0eb5e7596896f705861e687b9261
-
Tool: Pyflakes Processed Files: django_evolution/tests/db/sqlite3.py django_evolution/tests/db/postgresql.py django_evolution/mutators.py django_evolution/tests/test_preprocessing.py django_evolution/evolve.py django_evolution/tests/db/mysql.py Tool: PEP8 Style Checker Processed Files: django_evolution/tests/db/sqlite3.py django_evolution/tests/db/postgresql.py django_evolution/mutators.py django_evolution/tests/test_preprocessing.py django_evolution/evolve.py django_evolution/tests/db/mysql.py
- Change Summary:
-
Grammars now super good.
- Commit:
-
1f7432766b5f0eb5e7596896f705861e687b9261df2ba2007ab0b267a826092f0dc4af1164e92006
-
Tool: Pyflakes Processed Files: django_evolution/tests/db/sqlite3.py django_evolution/tests/db/postgresql.py django_evolution/mutators.py django_evolution/tests/test_preprocessing.py django_evolution/evolve.py django_evolution/tests/db/mysql.py Tool: PEP8 Style Checker Processed Files: django_evolution/tests/db/sqlite3.py django_evolution/tests/db/postgresql.py django_evolution/mutators.py django_evolution/tests/test_preprocessing.py django_evolution/evolve.py django_evolution/tests/db/mysql.py