Michael Bayer <[EMAIL PROTECTED]> writes: > On Feb 19, 2007, at 12:16 AM, David Bolen wrote: > > > > > 1. I have a simple "add" operation which does the basic object > > allocation, session.save() and session.flush(). (...) > > best practice when an error during flush() occurs is to clear the > session using session.clear() and start over. this is also the > advice of the hibernate camp which is what we've based our Session > on. SA does not make any assumptions whatsoever what youd like to do > with the objects in your session if a flush failed.
Hmm, but in that case though I'd also be clearing out objects that might be associated with the session but weren't involved in the current unit of work's change set (the current add operation). So I'd need some way to then re-associate (update()) other relevant objects. Although as you say, that's really an application level choice. I suppose in this case where I've got a better handle on the object actually being changed (the one being saved()), that expunging that one object might be the most effective approach, and is less effort than clearing and then re-updating all the other objects. Unless - should I be more liberal in my creation of sessions? That is, for this particular "add" operation would it actually be smarter to grab a new session to contain the objects involved? > > 2. I'm unclear what (if anything) to expect with respect to my object > > instances in memory post-save for primary key or default value > > columns. (...) > > > > Of course, then it bit me later when I found that my DateTime > > columns > > (with a default of func.current_timestamp()) of my instances had > > string values and not datetime as I expected. > > use func.current_timestamp(type=DateTime) Ah, ok. > > 3. I was implementing an archive of deleted objects, (...) > > I was excited to see the entity_name availability with alternate > > (...) > > Anyway, I was wondering if there was a clean way to use a single > > object instance in this way, or even a supported way of clearing an > > instance so SA doesn't think it used to be associated somewhere. > > havent put much thought into it, the easiest way is to just change > the "_entity_name" attribute to whatever, and if you remove > "_instance_key" then SA will see the instance as "pending" or > "transient" (meaning it will do an INSERT next time it tries to > persist it). just play around with dir(myobject) a little to see > what SA sticks on there. Sounds fine. That's more or less what I had experimented with but wasn't sure how stable twiddling with the SA attributes would be. But those sound fairly concrete :-) Thanks for the help. -- David --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
