Code

Opened 8 years ago

Closed 7 years ago

#1320 closed defect (duplicate)

django.views.generic.create_update.delete_object does not handle IntegrityError exception

Reported by: mattimustang@… Owned by: jacob
Component: Generic views Version: master
Severity: normal Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I'm getting the following exception thrown when I try and delete an object named 'My Company' that is set as the 'organisation' field for another object called 'My Contact'

Shouldn't delete_object handle this better?

IntegrityError at /directory/contacts/3/delete/
ERROR: update or delete on "directory_contacts" violates foreign key constraint "directory_contacts_organisation_id_fkey" on "directory_contacts" DETAIL: Key (id)=(3) is still referenced from table "directory_contacts". DELETE FROM "directory_contacts" WHERE "id"=3

The model that I have is:

class Contact(meta.Model):
    name = meta.CharField(maxlenth=32)
    organisation = meta.ForeignKey('self', null=True, blank=True)

Attachments (0)

Change History (4)

comment:1 Changed 8 years ago by gugu

whych sql are you using? i have two postgreses - on 7 this occurs, on 8 - not. (fresh-copied db)

comment:2 Changed 7 years ago by Simon G. <dev@…>

Can anyone else confirm this? is it a db(-version) specific issue (as suggested by gugu above)?

comment:3 Changed 7 years ago by Gary Wilson <gary.wilson@…>

  • Triage Stage changed from Unreviewed to Design decision needed

comment:4 Changed 7 years ago by mtredinnick

  • Resolution set to duplicate
  • Status changed from new to closed

The real crux of this has to be solved as part of #2288 -- it's a matter of how to handle errors when cascading delete behaviour varies. I suspect the answer is going to be that the user (developer) is responsible for checking for this when cascading deletes are not enabled, but I'm not sure how that will wash out in the end.

Closing this in favour of #2288.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


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

 
Note: See TracTickets for help on using tickets.