On Feb 12, 2014, at 1:49 AM, Wolfgang Schnerring <w...@gocept.com> wrote:

> On 11 Feb 2014 06:54:22 Michael Bayer <mike...@zzzcomputing.com> wrote:
>> On Feb 11, 2014, at 3:44 AM, Wolfgang Schnerring <w...@gocept.com> wrote:
>>>       parent = session.query(Parent).first()
>>>       self.assertEqual(1, len(parent.children))
>>>       session.begin_nested()
>>>       session.delete(parent.children[0])
>>>       self.assertEqual(0, len(parent.children))
>>> 
>>> 
>>> My point is, the last assertion fails, which I find both surprising and
>>> inconvenient. ;) I'd be grateful for any insights you have about this.
>> 
>> I’m pretty sure I mentioned this was what it seemed like you were
>> describing.  this is the “delete() on an object doesn’t remove it from all
>> collections in which it is contained”.  it’s not related to savepoints and
>> you can read about how to work with this behavior here:
>> http://docs.sqlalchemy.org/en/rel_0_9/orm/session.html#session-deleting-from-collections
> 
> I know that flush does not trigger expiry. ;) I was wondering whether 
> savepoints
> qualified as being a stronger boundary than flush and thus might be worthy of
> triggering expiry. But I guess that answers my question then: the current
> behaviour *is* intentional, and if I want expire_all then I'll just have to
> call it myself (which is fine, I guess).

well I’d look into using events if you’d like every begin_nested() to issue an 
expiry.  The after_transaction_create should be a good event to use: 
http://docs.sqlalchemy.org/en/rel_0_9/orm/events.html#sqlalchemy.orm.events.SessionEvents.after_transaction_create
  - check if the given SessionTransaction is “nested” by seeing if it has a 
non-None ._parent attribute.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to