Opened 4 years ago

Closed 4 years ago

#32262 closed Bug (fixed)

squashmigrations does not unset model options when optimizing CreateModel and AlterModelOptions

Reported by: InvalidInterrupt Owned by: Hasan Ramezani
Component: Migrations Version: 2.2
Severity: Normal Keywords:
Cc: InvalidInterrupt 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

When an operation resembling AlterModelOptions(name="test_model", options={}) is squashed into the corresponding CreateModel operation, model options are not cleared on the resulting new CreateModel operation object.

CreateModel.reduce() sets the new options as options={**self.options, **operation.options} in this case (django/db/migrations/operations/models.py line 144 on commit 991dce4f), with no logic to remove options not found in operation.options as is found in AlterModelOptions.state_forwards().

I believe this issue still exists on the master branch based on my reading of the code, but I've only tested against 2.2.

Change History (5)

comment:1 by InvalidInterrupt, 4 years ago

Cc: InvalidInterrupt added

comment:2 by Simon Charette, 4 years ago

Triage Stage: UnreviewedAccepted

Makes sense, I guess we should take AlterModelOptions.ALTER_OPTION_KEYS in consideration here like AlterModelOptions.state_forwards does

https://github.com/django/django/blob/991dce4fc5b656e04af08a595181bd576f2bd857/django/db/migrations/operations/models.py#L675-L677

comment:3 by Hasan Ramezani, 4 years ago

Has patch: set
Owner: changed from nobody to Hasan Ramezani
Status: newassigned

comment:4 by Mariusz Felisiak, 4 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In 8d582bf:

Fixed #32262 -- Fixed migration optimization for model creation and Meta options removal.

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