Opened 7 months ago

Closed 6 months ago

Last modified 6 months ago

#30330 closed Bug (fixed)

delete() on instances of models without any dependencies doesn't clear PKs.

Reported by: Artur Owned by: nobody
Component: Database layer (models, ORM) Version: 2.2
Severity: Release blocker Keywords: delete, pk
Cc: Florian Apolloner 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

Deleting any model with no dependencies not updates the PK on the model. It should be set to None after .delete() call.

See Django.db.models.deletion:276-281. Should update the model line 280.

Attachments (2)

test-30330.diff (1.1 KB) - added by felixxm 7 months ago.
Regression test.
fix-30330.diff (657 bytes) - added by Florian Apolloner 7 months ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 7 months ago by felixxm

Cc: Florian Apolloner added
Severity: NormalRelease blocker
Summary: Deletion isn't updating modeldelete() on instances of models without any dependencies doesn't clear PKs.
Triage Stage: UnreviewedAccepted

Reproduced at 1ffddfc233e2d5139cc6ec31a4ec6ef70b10f87f.

Regression in bc7dd8490b882b2cefdc7faf431dc64c532b79c9.

Thanks for the report.

Changed 7 months ago by felixxm

Attachment: test-30330.diff added

Regression test.

Changed 7 months ago by Florian Apolloner

Attachment: fix-30330.diff added

comment:3 Changed 7 months ago by Florian Apolloner

I have attached a simple fix which mimics what https://github.com/django/django/blob/master/django/db/models/deletion.py#L324-L326 does for multiple objects. I am not sure if we need https://github.com/django/django/blob/master/django/db/models/deletion.py#L320-L323 (the block above) because I think field_updates is only ever filled if the objects are not fast-deletable -- ie https://github.com/django/django/blob/master/django/db/models/deletion.py#L224 is not called due to the can_fast_delete check at the beginning of the collect function.

That said, if we want to be extra "safe" we can just move lines 320 - 326 into an extra function and call that from the old and new location (though I do not think it is needed).

comment:5 Changed 7 months ago by Florian Apolloner

Has patch: set

comment:6 Changed 7 months ago by Simon Charette

Triage Stage: AcceptedReady for checkin

comment:7 Changed 6 months ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: newclosed

In afc708c:

Fixed #30330 -- Fixed setting of primary key to None during fast-delete.

Regression in bc7dd8490b882b2cefdc7faf431dc64c532b79c9.

comment:8 Changed 6 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In b88ffef7:

[2.2.x] Fixed #30330 -- Fixed setting of primary key to None during fast-delete.

Regression in bc7dd8490b882b2cefdc7faf431dc64c532b79c9.

Backport of afc708cf6d047b35db57bd7c55baeffef459d279 from master

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