the event that corresponds most directly here is the do_orm_execute() event:
https://docs.sqlalchemy.org/en/14/orm/session_events.html#session-execute-events you would want to use the "re-execute statement" feature described at: https://docs.sqlalchemy.org/en/14/orm/session_events.html#re-executing-statements the example there is a little more complex than what you need. you would have something more like: @event.listens_for(Session, "do_orm_execute") def _do_orm_execute(orm_execute_state): if orm_execute_state.is_orm_statement: result = orm_execute_state.invoke_statement() rdbm_events.run_created() return result On Tue, Apr 27, 2021, at 12:35 PM, Mike Bernson wrote: > I am moving from version 1.0.14 to version 1.4.11 of sqlalchemy. > > I need to get a callback when all of the data from orm query is loaded not > just single instance. > > In the 1.0 version I created the session using query_cls: > > self.session = Session(bind=engine, autoflush=False, > _enable_transaction_accounting=False, autocommit=True, > query_cls=my_query) > > and the query class > class my_query(Query): > > def _execute_and_instances(self, context): > results = list(super(my_query, self)._execute_and_instances(context)) > rdbm_events.run_created() > for instance in results: > yield instance > > def instances(self, cusor, __context=None): > results = list(super(my_query, self).instances(cusor, __context)) > rdbm_events.run_created() > for instance in results: > yield instance > > This does not work for 1.4.11. > What is the best way to get a callback when all > the data from query or lazy/deferred loaded into instances ? > > -- > 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 > <mailto:sqlalchemy%2Bunsubscribe%40googlegroups.com>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sqlalchemy/164552c2-f11a-526b-abae-a8287afdf3e6%40mlb.org. > -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/1422b5e7-e15f-49ed-894c-9ba718a6f0f3%40www.fastmail.com.