Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#26881 closed Bug (fixed)

Crash when creating migrations with managers having use_in_migrations=True

Reported by: Claude Paroz Owned by: nobody
Component: Migrations Version: 1.10
Severity: Release blocker Keywords:
Cc: Loic Bistuer Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Considering this model layout:

from django.db import models


class PersonManager(models.Manager):
    use_in_migrations = True


class Person(models.Model):
    name = models.CharField(max_length=10)

    objects = PersonManager()

    class Meta:
        abstract = True


class BossManager(PersonManager):
    use_in_migrations = True


class Boss(Person):
    objects = BossManager()

Django 1.10 crashes when calling makemigrations:

  ...
  File "/home/claude/virtualenvs/djangogit/local/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 172, in _detect_changes
    self.generate_created_models()
  File "/home/claude/virtualenvs/djangogit/local/lib/python2.7/site-packages/django/db/migrations/autodetector.py", line 553, in generate_created_models
    managers=model_state.managers,
  File "/home/claude/virtualenvs/djangogit/local/lib/python2.7/site-packages/django/db/migrations/operations/models.py", line 64, in __init__
    _check_for_duplicates('managers', (name for name, _ in self.managers))
  File "/home/claude/virtualenvs/djangogit/local/lib/python2.7/site-packages/django/db/migrations/operations/models.py", line 20, in _check_for_duplicates
    "Found duplicate value %s in CreateModel %s argument." % (val, arg_name)
ValueError: Found duplicate value objects in CreateModel managers argument.

while Django 1.9 creates the migration without problem.

Change History (6)

comment:2 by Tim Graham, 8 years ago

Cc: Loic Bistuer added
Triage Stage: UnreviewedAccepted

comment:3 by Loic Bistuer, 8 years ago

comment:4 by Claude Paroz, 8 years ago

Has patch: set
Triage Stage: AcceptedReady for checkin

Thanks Loïc for your quick reaction!

comment:5 by Loïc Bistuer <loic.bistuer@…>, 8 years ago

Resolution: fixed
Status: newclosed

In dab83e5b:

Fixed #26881 -- Fixed duplicate managers in migrations.

When both parent and child models had managers with the same name and
a migrations opt-in both were added to the migration state.

comment:6 by Loïc Bistuer <loic.bistuer@…>, 8 years ago

In a2af242:

[1.10.x] Fixed #26881 -- Fixed duplicate managers in migrations.

When both parent and child models had managers with the same name and
a migrations opt-in both were added to the migration state.

Backport of dab83e5ba108c08a04ae400ac5354fd73e26c6f5 from master

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