Add support for modern Django app labels.

Review Request #10552 — Created May 13, 2019 and submitted

Information

Django Evolution
master
84bb0de...

Reviewers

One of the big blockers for modern Django support has been the way in
which app labels have changed. In Django 1.6 and earlier, app labels
were based on an app's module name, and while discouraged, it was
technically legal for multiple apps to share the same name. Django 1.7's
introduction of the app registry and AppConfig classes changed this,
allowing app labels to be more flexible, and removed any support for
duplicate labels.

The Django Evolution project signature grouped models by legacy app
labels, and this meant that it was possible for one app entry to have
models for multiple apps.

This change introduces proper support for modern app labels. Now, both
the legacy app label and the modern app label (which will be the same
thing as the legacy app label on Django 1.6 or older) are stored as part
of the app's signature. When looking up an app signature, either a
modern or legacy app label can be used, with the modern label taking
precedence.

If the app label is changed, a RenameAppLabel mutation can be added to
an app's evolutions to tell Django Evolution about the old label, new
label, and the current value for the legacy label. It can also take a
list of explicit model names, in case the app's entry needs to be split.
This mutation will create a new app signature for the new app label,
move over any relevant models to it, and delete the old app signature
(if now empty).

When generating a hinted diff, Django Evolution will attempt to find any
renamed apps and generate suitable RenameAppLabel mutations.

The optimizer factors in any RenameAppLabel mutations, updating any
other mutations to use the correct app label and collapsing down
multiple mutations into one final one.

Unit tests pass on Django 1.6 (Python 2.7) and Django 1.11 (Python 2.7
and 3.7).

Tested manually with a simulated Review Board 3.0 to 4.0 upgrade on
Django 1.6 and on 1.11). Verified that on 1.6, it behaved as before.
On 1.11, it noticed the renamed app labels in Djblets and included them
in the hints and diffs. It also applied any listed in those apps'
evolution sequences.

Description From Last Updated

F401 'django_evolution.compat.apps.get_apps' imported but unused

reviewbotreviewbot

F401 'django_evolution.compat.models.get_model_name' imported but unused

reviewbotreviewbot

F401 'django_evolution.compat.models.get_models' imported but unused

reviewbotreviewbot

F401 'django_evolution.utils.apps.get_app_label' imported but unused

reviewbotreviewbot

E123 closing bracket does not match indentation of opening bracket's line

reviewbotreviewbot

model name -> module name

daviddavid

model name -> module name

daviddavid

model name -> module name

daviddavid

model name -> module name

daviddavid
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

chipx86
david
  1. 
      
  2. django_evolution/mutations.py (Diff revision 2)
     
     
    Show all issues

    model name -> module name

  3. django_evolution/mutators.py (Diff revision 2)
     
     
    Show all issues

    model name -> module name

  4. django_evolution/mutators.py (Diff revision 2)
     
     
    Show all issues

    model name -> module name

  5. django_evolution/mutators.py (Diff revision 2)
     
     
    Show all issues

    model name -> module name

  6. 
      
chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to master (f631a59)