Thanks a lot Mike!

вт, 18 вер. 2018 о 16:07 Mike Bayer <mike...@zzzcomputing.com> пише:

> On Tue, Sep 18, 2018 at 7:07 AM Dmytro Starosud <d.staro...@gmail.com>
> wrote:
> >
> > Hello group
> >
> > Please help me with the following. Imagine I have:
> >
> > @event.listens_for(Session, 'before_flush')
> > def one(session, flush_context, instances):
> >     pass
> >
> >
> > @event.listens_for(Session, 'before_flush')
> > def two(session, flush_context, instances):
> >     pass
> >
> >
> > I.e. two handlers for the same target/identifier are registered in a row.
> > Will they be executed in the order they registered?
> > Is this order actually strictly specified?
> > Documentation link would be great, as I failed to find this in docs.
>
> The handlers are registered in order and are called in the order they
> were registered.   however it's not quite in the "spirit" of the event
> system to rely upon this.   For example, someone could someday be
> refactoring your code above and then "two" gets placed above "one",
> since these are two functions that don't have any obvious relationship
> to each other.   So I wouldn't recommend that pattern just from a
> Python perspective.
>
> if you have two event handling functions with a dependency between
> each other, it's much better to make this explicit in your code, and
> do something like:
>
> @event.listens_for(Session, "before_flush")
> def both(...):
>     one(...)
>     two(...)
>
>
>
> >
> > Thanks a lot in advance!
> > Best regards
> > Dmytro
> >
> >
> > --
> > SQLAlchemy -
> > The Python SQL Toolkit and Object Relational Mapper
> >
> > http://www.sqlalchemy.org/
> >
> > To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> > ---
> > 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 sqlalchemy+unsubscr...@googlegroups.com.
> > To post to this group, send email to sqlalchemy@googlegroups.com.
> > Visit this group at https://groups.google.com/group/sqlalchemy.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example.  See  http://stackoverflow.com/help/mcve for a full
> description.
> ---
> 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 sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to