Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#25852 closed Bug (fixed)

Batch migrations fail when dependent on a custom manager

Reported by: lightstrike Owned by: Simon Charette
Component: Migrations Version: 1.8
Severity: Normal Keywords:
Cc: Simon Charette 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

Running a migration containing a RunPython operation that relies on a custom manager assigned using migrations.alterModelManagers in a previous migration within a batch migration sequences results in a AttributeError being thrown. Running the migration that assigns a new manager in a separate manage.py migrate command as the command that contains the RunPython operation succeeds as expected.

This issue was first raised in a Stack Overflow post in March. One of the answers contains a workaround but this is less than ideal.

A sample app was created that shows this bug in action. To reproduce:

  1. Create new Django project & copy ticket_geoff app in root project directory.
  2. Add ticket_geoff to INSTALLED_APPS
  3. Run python manage.py migrate - note AssertionError
  4. Run python manage.py migrate - this time it's okay

Another way to reproduce, showing that running the migration that changes model managers and running the migration with the RunPython command in separate migrate commands runs successfully:

  1. Create new Django project & copy ticket_geoff app in root project directory.
  2. Run python manage.py migrate - sets up base tables
  3. Add ticket_geoff to INSTALLED_APPS
  4. Run python manage.py migrate ticket_geoff 0003 - all good
  5. Run python manage.py migrate ticket_geoff - fine

Special thanks to Django NYC for helping review this ticket

Change History (10)

comment:1 by Simon Charette, 9 years ago

Cc: Simon Charette added
Triage Stage: UnreviewedAccepted

comment:2 by Simon Charette, 9 years ago

Owner: changed from nobody to Simon Charette
Status: newassigned

comment:3 by Simon Charette, 9 years ago

Came up with a patch.

comment:4 by Simon Charette, 9 years ago

Has patch: set

comment:5 by Markus Holtermann, 9 years ago

Needs documentation: set
Triage Stage: AcceptedReady for checkin

Patch looks good to me, just needs a release note in 1.8 since its a bug in a newly introduced feature which makes the feature pretty broken.

comment:6 by Simon Charette, 9 years ago

Needs documentation: unset
Triage Stage: Ready for checkinAccepted

Added release notes.

comment:7 by Tim Graham, 9 years ago

Triage Stage: AcceptedReady for checkin

comment:8 by Simon Charette <charette.s@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In c4e372a:

Fixed #25852 -- Made sure AlterModelManager forces a reload of its model state.

Thanks to Geoffrey Sechter and the Django NYC group for the report and Markus
for the review.

comment:9 by Simon Charette <charette.s@…>, 9 years ago

In c4c72ade:

[1.9.x] Fixed #25852 -- Made sure AlterModelManager forces a reload of its model state.

Thanks to Geoffrey Sechter and the Django NYC group for the report and Markus
for the review.

Backport of c4e372aaf467ae41315cfe56a718a80469fc5318 from master

comment:10 by Simon Charette <charette.s@…>, 9 years ago

In 4b02b433:

[1.8.x] Fixed #25852 -- Made sure AlterModelManager forces a reload of its model state.

Thanks to Geoffrey Sechter and the Django NYC group for the report and Markus
for the review.

Backport of c4e372aaf467ae41315cfe56a718a80469fc5318 from master

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