Opened 6 months ago

Last modified 6 days ago

#21257 new New feature

ForeignKey on_delete functionality should traverse (cascade, ha ha) to the DB backend

Reported by: gcbirzan Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


By default, django creates FKs without an explicit ON DELETE on the backend. This, if nothing else, should be configurable. If for no other reason that when using some transaction isolation modes, the error returned by the backend will be the wrong one during concurrent modifications:

Table b links to table a. You insert in table b a link to ID 1 in a, at the same time as you delete it from a.

With the default (at least in PostgreSQL), in REPEATABLE READ, the error is IntegrityError, which is wrong, since in fact you should just retry the transaction. In lower isolation levels, the FK is deleted (as expected), though, granted the on delete signals are not called.

Attachments (0)

Change History (4)

comment:1 Changed 6 months ago by mjtamlyn

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

This is likely related to the mailing list conversation and the ticket #21127. Basically the consensus seems to be that if we do push to the database it will be a new option to on_delete in the FK declaration. This is also likely to be bundled with the removal of a default behaviour for on_delete.

comment:2 Changed 6 months ago by mjtamlyn

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 6 months ago by anonymous

I think the URL should be!topic/django-developers/FJMoGgtYIX4

Anyway, it is, but this doesn't involve any default behaviour change, so it should be way easier.

comment:4 Changed 6 days ago by timo

  • Component changed from Uncategorized to Database layer (models, ORM)

Add Comment

Modify Ticket

Change Properties
<Author field>
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.