#23041 closed Bug (fixed)

Double proxy models break migrations

Reported by: maikhoepfel Owned by: andrewgodwin
Component: Migrations Version: 1.7-rc-1
Severity: Release blocker Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'm working on adding Django 1.7 support to django-oscar. We have two layers of proxy models on top of a Benefit model. That is unorthodox and maybe not the best design decision, but worked in Django before 1.7. It breaks when trying to apply new-style migrations.

This happens both with the release candidate and a checkout from stable/1.7.x.

As a minimal test case, I created a new Django project and app, and have the following models:

from django.db import models

class Benefit(models.Model):

    # not needed, just showing that the model isn't empty
    type = models.CharField("Type", max_length=128, blank=True)


class ShippingBenefit(Benefit):

    class Meta:
        proxy = True


class ShippingAbsoluteDiscountBenefit(ShippingBenefit):


    class Meta:
        proxy = True

I then run rm -r testapp/migrations/ db.sqlite3 && ./manage.py makemigrations testapp && ./manage.py migrate to reproduce:

Migrations for 'testapp':
  0001_initial.py:
    - Create model Benefit
    - Create proxy model ShippingAbsoluteDiscountBenefit
    - Create proxy model ShippingBenefit
Operations to perform:
  Apply all migrations: admin, contenttypes, testapp, auth, sessions
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying auth.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying sessions.0001_initial... OK
  Applying testapp.0001_initial...Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/core/management/base.py", line 337, in execute
    output = self.handle(*args, **options)
  File "/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 160, in handle
    executor.migrate(targets, plan, fake=options.get("fake", False))
  File "/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 62, in migrate
    self.apply_migration(migration, fake=fake)
  File "/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 96, in apply_migration
    migration.apply(project_state, schema_editor)
  File "/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 107, in apply
    operation.database_forwards(self.app_label, schema_editor, project_state, new_state)
  File "/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/db/migrations/operations/models.py", line 33, in database_forwards
    apps = to_state.render()
  File "/home/m/.virtualenvs/proxyfun/local/lib/python2.7/site-packages/django/db/migrations/state.py", line 71, in render
    raise InvalidBasesError("Cannot resolve bases for %r\nThis can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)\n in an app with no migrations; see https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies for more" % new_unrendered_models)
django.db.migrations.state.InvalidBasesError: Cannot resolve bases for [<ModelState: 'testapp.ShippingAbsoluteDiscountBenefit'>]
This can happen if you are inheriting models from an app with migrations (e.g. contrib.auth)
 in an app with no migrations; see https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies for more

Change History (3)

comment:1 Changed 14 months ago by andrewgodwin

  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to andrewgodwin
  • Patch needs improvement unset
  • Severity changed from Normal to Release blocker
  • Status changed from new to assigned

comment:2 Changed 14 months ago by Andrew Godwin <andrew@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 145d231782172301e25521d12efc54c52258bc92:

Fixed #23041: Bad base dependencies for proxy models

comment:3 Changed 14 months ago by Andrew Godwin <andrew@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In de709001c45c6646ecf39689949e3011ae5be197:

[1.7.x] Fixed #23041: Bad base dependencies for proxy models

Note: See TracTickets for help on using tickets.
Back to Top