Thanks again for the help.

 your code isn’t working because somehow you’ve dug in and bypassed all the
> public history APIs to find one that is internal to the flush context and
> is actually cached.
>

The docs for after_flush link to the docs for UOWTransaction, which is
where I found the info on get_attribute_history:
http://docs.sqlalchemy.org/en/latest/orm/internals.html#sqlalchemy.orm.session.UOWTransaction

The docs have very little practical info on how to access interesting data
in an after_flush event, and google has not turned up any example code, so
hopefully this gist that I'm building up will help some people out.

I've updated my gist <https://gist.github.com/chadrik/08617b6ed4d9cbacd93c>
to demonstrate another problem:  even when using load_history() the remote
side of a many-to-one relationship is not updated.

for example, if I move a chapter from one book to the other...

chapter.book = book1
session.commit()

... then the printed output is:

Book(1) no relationships updated Chapter(u'Intro to Book2') added: 'book'
[Book(1)]

However, if I access the remote relationships before committing, like
this...

print book1.chapters
print book2.chapters
chapter.book = book1
session.commit()

...then the output is what I'd expect:

Book(1) added: 'chapters' [Chapter(u'Intro to Book2')] Book(2) deleted:
'chapters' [Chapter(u'Intro to Book2')] Chapter(u'Intro to Book2') added:
'book' [Book(1)] deleted: 'book' [Book(2)]

How can I trigger the history of these relationships to be updated from
within after_flush?

thanks again,
chad

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to