#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:
- Create new Django project & copy
ticket_geoffapp in root project directory. - Add
ticket_geofftoINSTALLED_APPS - Run
python manage.py migrate- note AssertionError - 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:
- Create new Django project & copy
ticket_geoffapp in root project directory. - Run
python manage.py migrate- sets up base tables - Add
ticket_geofftoINSTALLED_APPS - Run
python manage.py migrate ticket_geoff 0003- all good - Run
python manage.py migrate ticket_geoff- fine
Special thanks to Django NYC for helping review this ticket
Change History (10)
comment:1 by , 10 years ago
| Cc: | added |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 10 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
comment:3 by , 10 years ago
comment:4 by , 10 years ago
| Has patch: | set |
|---|
comment:5 by , 10 years ago
| Needs documentation: | set |
|---|---|
| Triage Stage: | Accepted → Ready 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 , 10 years ago
| Needs documentation: | unset |
|---|---|
| Triage Stage: | Ready for checkin → Accepted |
Added release notes.
comment:7 by , 10 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Came up with a patch.