The flush events only fire off if there's actually something to be flushed.  It 
would be inefficient for the events to be emitted for every flush() as flush is 
in fact called a great number of times, on every query, assuming autoflush 
enabled.  For this reason a flush() with a session that has no change events of 
any kind quickly checks some flags and returns.     

Think of before_flush() really being called before_flush_on_pending_changes() 
if that helps.

I'll check the docstrings to see if any clarification is needed.





On Jun 25, 2011, at 4:33 AM, kost BebiX wrote:

> I've created this question at stackoverflow 
> http://stackoverflow.com/questions/6476652/sqlalchemy-0-6-5-and-0-6-8-sessionextension-after-flush-doesnt-gets-called
>  , but I thought maybe I should also ask here.
> 
> I don't get it, but this code doesn't call 
> after_flush/before_flush/after_flush_postexec
> 
> # -*- coding: utf-8 -*-
> 
> from sqlalchemy.orm import scoped_session, sessionmaker
> from sqlalchemy.orm.interfaces import SessionExtension
> 
> class AfterFlushExtension(SessionExtension):
>     def before_commit(self, session):
>         print "> before_commit"
> 
>     def after_commit(self, session):
>         print "> after_commit"
> 
>     def before_flush(self, session, flush_context, instances):
>         print '> before_flush'
> 
>     def after_flush(self, session, flush_context):
>         print '> after_flush'
> 
>     def after_flush_postexec(self, session, flush_context):
>         print '> after_flush_postexec'
> 
> session = scoped_session(sessionmaker(extension=AfterFlushExtension()))
> session.flush()
> session.commit()
> And a result:
> 
> $ python ~/Dropbox/playground/python/sqlalchemy_hook_test/main.py 
> > before_commit
> > after_commit




> 
> Thank you.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/sqlalchemy/-/40uHGUoHJ1sJ.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to