Opened 19 years ago

Closed 18 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: dev
Severity: normal Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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)

Change History (4)

comment:1 by gugu, 19 years ago

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

comment:2 by Simon G. <dev@…>, 18 years ago

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

comment:3 by Gary Wilson <gary.wilson@…>, 18 years ago

Triage Stage: UnreviewedDesign decision needed

comment:4 by Malcolm Tredinnick, 18 years ago

Resolution: duplicate
Status: newclosed

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.

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