[sqlalchemy] Re: Setting instrument list items

2008-01-17 Thread jason kirtland
Rick Morrison wrote: I'm having trouble with the instrumented lists used for relation collections: def setProp(self, new_prop, exclusive=True): self.props = [p for p if p.typ != new_prop.typ] self.props.append(new_prop) so if 'props' is a relation on some mapped class, and I

[sqlalchemy] Re: Setting instrument list items

2008-01-17 Thread Rick Morrison
def setProp(self, new_prop, exclusive=True): if exclusive: self.props = [p for p if p.typ != new_prop.typ] self.props.append(new_prop) o = MappedObject() o.setProp(Prop(typ='a', val='b') o.setProp(Prop(typ='b', val='c') MappedObject has a simple relation() for Prop. at flush()

[sqlalchemy] Re: Setting instrument list items

2008-01-17 Thread jason kirtland
Rick Morrison wrote: def setProp(self, new_prop, exclusive=True): if exclusive: self.props = [p for p if p.typ != new_prop.typ] self.props.append(new_prop) o = MappedObject() o.setProp(Prop(typ='a', val='b') o.setProp(Prop(typ='b', val='c') MappedObject has a simple

[sqlalchemy] Re: Setting instrument list items

2008-01-17 Thread Rick Morrison
two clarifications: in my case the relation cascade is 'all, delete-orphan'. But in the case I'm running into, all of the children are unpersisted before the flush. and the exception I get is not a complaint about an orphan, it's a database error when SA tries to persist the (typ='a') item, but

[sqlalchemy] Re: Setting instrument list items

2008-01-17 Thread Michael Bayer
On Jan 17, 2008, at 7:32 PM, jason kirtland wrote: I don't think the discussion about discarding unpersisted collection orphans made the hop onto the list (IRC only) - anyone have an opinion? I think I'm still in favor of quashing this exception. yeah just tell me what youd like to

[sqlalchemy] Re: Setting instrument list items

2008-01-17 Thread jason kirtland
Rick Morrison wrote: On Jan 17, 2008 7:32 PM, jason kirtland [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Rick Morrison wrote: def setProp(self, new_prop, exclusive=True): if exclusive: self.props = [p for p if p.typ != new_prop.typ]

[sqlalchemy] Re: Setting instrument list items

2008-01-17 Thread Michael Bayer
On Jan 17, 2008, at 7:36 PM, Rick Morrison wrote: two clarifications: in my case the relation cascade is 'all, delete- orphan'. But in the case I'm running into, all of the children are unpersisted before the flush. and the exception I get is not a complaint about an orphan, it's a

[sqlalchemy] Re: Setting instrument list items

2008-01-17 Thread Michael Bayer
On Jan 17, 2008, at 7:51 PM, Rick Morrison wrote: An expunge on an collection remove that creates an orphan wouldn't be a surprise to me; I'm surprised that it doesn't do that now. +1 for error on case 1 plus auto-remove in case 2 would the expunge happen at attribute change time or at

[sqlalchemy] Re: Setting instrument list items

2008-01-17 Thread Michael Bayer
On Jan 17, 2008, at 8:03 PM, Michael Bayer wrote: On Jan 17, 2008, at 7:51 PM, Rick Morrison wrote: An expunge on an collection remove that creates an orphan wouldn't be a surprise to me; I'm surprised that it doesn't do that now. +1 for error on case 1 plus auto-remove in case 2

[sqlalchemy] Re: Setting instrument list items

2008-01-17 Thread Rick Morrison
do your setProp() operation, then do this: (added, unchanged, deleted) = MyClass.props.get_history(myobject) to see whats actually in there. it should just be a collection of added objects (and also, the correct objects). Yep, so far so good. Two Prop items in 'added' Then, use

[sqlalchemy] Re: Setting instrument list items

2008-01-17 Thread Rick Morrison
OK, I get the basic idea; expunge isn't automatic. Let me rework the setProp to get things running again here, and then I'll pick up the discussion about that. For the archives: This rework sidesteps the issue: def setProp(self, prop, exclusive=True): if exclusive: curprops = [p