Fix evolution optimization issues when renaming models.

Review Request #8085 — Created March 30, 2016 and submitted

Information

Django Evolution
release-0.7.x
df2ba20...

Reviewers

Django Evolution's evolution optimization code had issues when applying
a series of evolutions that add a ForeignKey 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 a KeyError.

This was partly caused by the optimization code not attempting to update
the related_model attribute of the new field when merging field
attributes, and partly due to the RenameModel 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 the RenameModel is always present in the
optimization steps, and making sure that related_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.

Description From Last Updated

list comprehension redefines 'model_name' from line 722

reviewbotreviewbot

list comprehension redefines 'model_name' from line 638

reviewbotreviewbot

This sentence isn't 100% grammar.

daviddavid
reviewbot
  1. 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
    
    
  2. django_evolution/mutators.py (Diff revision 1)
     
     
    Show all issues
     list comprehension redefines 'model_name' from line 722
    
  3. 
      
chipx86
reviewbot
  1. 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
    
    
  2. django_evolution/mutators.py (Diff revision 2)
     
     
    Show all issues
     list comprehension redefines 'model_name' from line 638
    
  3. 
      
chipx86
reviewbot
  1. 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
    
    
  2. 
      
david
  1. 
      
  2. django_evolution/mutators.py (Diff revision 3)
     
     
     
     
    Show all issues

    This sentence isn't 100% grammar.

    1. It's 100% some kind of grammar!

  3. 
      
chipx86
reviewbot
  1. 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
    
    
  2. 
      
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-0.7.x (5ce1c47)