Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » delete(), cascade, and the case of the missing data [RSS Feed]

#1 Dec. 5, 2005 20:47:06

Jeffrey E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

delete(), cascade, and the case of the missing data


Howdy all,There are tangential references to this on the list archives andelsewhere, but I haven't found any describing this specific situation:In short, if I have a model object type with both 'simple' sub-objects (objects with a single ForeignKey to the main object and noother references) and 'complex' foreign key relations with peerobjects (which are not wholly owned by the main object, but do have aForeignKey reference to it somewhere), and I try delete()-ing my mainobject, I end up with the simple objects being fully deleted, but mymain object is _not_ deleted due to the 'complex' relationalintegrity constraints.The end result is that an attempt to delete the record ultimatelyfails--which is what I want, due to the constraints--but because theoverall deletion process "half-occurred", I have lost data in theprocess! This is bad.Since transactions aren't in yet, I can't think of another way toprevent this from happening--don't know if I am doing somethingincorrectly, or what :)That's the gist of it; the concrete example follows, if you'reinterested (unnecessary info stripped out):==== apps/contacts/models/contacts.py ====

class Contact(meta.Model):
# Reference to employee who provided the firm with thiscontact's infoprovider = meta.ForeignKey('self',null=True,limit_choices_to={'company__name__exact':OUR_COMPANY})# Reference to user/employee who last updated this contact record
mod_user = meta.ForeignKey('self',blank=True,null=True)


class Address(meta.Model):
# 'Parent' reference to the contact this address belongs tocontact = meta.ForeignKey(Contact,edit_inline=meta.STACKED,max_num_in_admin=3,min_num_in_admin=3)


==== ipython session ====

In : from django.models.contacts import contactsIn : me = contacts.get_object(first__exact='Jeffrey',last__exact='Forcier')In : me
Out: Forcier, Jeffrey E.

In : me.get_address_list
------> me.get_address_list()
Out:

In :
Out:

In : me.delete()##### These 3 lines are from a debug statement I had inserted intodelete() ####DELETE FROM "contacts_addresses" WHERE "id"=%s
DELETE FROM "contacts_addresses" WHERE "id"=%s
DELETE FROM "contacts_contacts" WHERE "id"=%s ---------------------------------------------------------------------------psycopg.IntegrityError Traceback (mostrecent call last)IntegrityError: ERROR: update or delete on "contacts_contacts"violates foreign key constraint "contacts_contacts_provider_id_fkey"on "contacts_contacts"DETAIL: Key (id)=(1247) is still referenced from table"contacts_contacts".DELETE FROM "contacts_contacts" WHERE "id"=1247



Thanks, sorry for the length,
Jeff

--
Jeffrey E. Forcier
Junior Developer, Research and Development
Stroz Friedberg, LLC
15 Maiden Lane, 12th Floor
New York, NY 10038
212-981-6540 212-981-6546http://www.strozllc.comThis message is for the named person's use only. It may contain
confidential, proprietary or legally privileged information. No right to
confidential or privileged treatment of this message is waived or lost
by any error in transmission. If you have received this message in
error, please immediately notify the sender by e-mail or by telephone at
212.981.6540, delete the message and all copies from your system and
destroy any hard copies. You must not, directly or indirectly, use,
disclose, distribute, print or copy any part of this message if you are
not the intended recipient.

Offline

#2 Dec. 6, 2005 01:15:17

Robert W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

delete(), cascade, and the case of the missing data


There really is no sensible way around the requirement for transactions,
unless you want to check every constraint yourself.

It is planned to go in before 0.91, AFAIK.

Offline

#3 Dec. 6, 2005 01:19:31

Jeffrey E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

delete(), cascade, and the case of the missing data


Yea, I was afraid that was it, just wanted to make sure I wasn'tmissing something silly/obvious.I need to put some code out the door tomorrow, which is why I askednow instead of just waiting for transactions to go in; I guess itwon't hurt too much to quickly patch the relevant method in core/meta/__init__ (or something) and then update the code later aftertransactions come out.Thanks,
Jeff

On Dec 5, 2005, at 8:12 PM, Robert Wittams wrote:There really is no sensible way around the requirement fortransactions,unless you want to check every constraint yourself.

It is planned to go in before 0.91, AFAIK.--
Jeffrey E. Forcier
Junior Developer, Research and Development
Stroz Friedberg, LLC
15 Maiden Lane, 12th Floor
New York, NY 10038
212-981-6540 212-981-6546http://www.strozllc.comThis message is for the named person's use only. It may contain
confidential, proprietary or legally privileged information. No right to
confidential or privileged treatment of this message is waived or lost
by any error in transmission. If you have received this message in
error, please immediately notify the sender by e-mail or by telephone at
212.981.6540, delete the message and all copies from your system and
destroy any hard copies. You must not, directly or indirectly, use,
disclose, distribute, print or copy any part of this message if you are
not the intended recipient.

Offline

  • Root
  • » Django
  • » delete(), cascade, and the case of the missing data [RSS Feed]

Board footer

Moderator control

Enjoy the 24th of April
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support