On Tue, Sep 12, 2017 at 1:42 PM, Colton Allen <cmanalle...@gmail.com> wrote: > In an attempt to simplify my app's logic, I want to move some mandatory > method calls into a model event. Traditionally, I've used "after_insert" > but it has some quirks in that you need to use the "connection" argument to > make updates. What I really want is more flexibility. I'll need use of my > "db.session" property, for example. I want it to behave like any other part > of my app.
you want to use after_flush_postexec(), you can use the session more or less normally: http://docs.sqlalchemy.org/en/latest/orm/session_events.html#after-flush-postexec > > A contrived example of the flow I have: > > model = EventedModel() > session.add(model) > session.commit() > > some_function_call(model) > > Versus the flow I want: > > @event.listens_for(EventedModel, 'after_commit') > def test(my_committed_model, *args, **kwargs): > some_function_call(my_committed_model) > > -- > 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.