Opened 8 years ago

Closed 8 years ago

Last modified 8 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 Changed 8 years ago by Simon Charette

Cc: Simon Charette added
Triage Stage: UnreviewedAccepted

comment:2 Changed 8 years ago by Simon Charette

Owner: changed from nobody to Simon Charette
Status: newassigned

comment:3 Changed 8 years ago by Simon Charette

Came up with a patch.

comment:4 Changed 8 years ago by Simon Charette

Has patch: set

comment:5 Changed 8 years ago by Markus Holtermann

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 Changed 8 years ago by Simon Charette

Needs documentation: unset
Triage Stage: Ready for checkinAccepted

Added release notes.

comment:7 Changed 8 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

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

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 Changed 8 years ago by Simon Charette <charette.s@…>

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 Changed 8 years ago by Simon Charette <charette.s@…>

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