That callback look like it happening before orm instances are created. I am 
looking for a
callback that is after all the instances are created. I am using the events to 
get a list of instances
that need work done when they are loaded from the database.

I need the instance data and relationship data filled in before run_created is 
called.

 listen(mapper, 'load', self.load_instance)
 listen(mapper, 'refresh', self.refresh_instance)


On 4/27/21 1:20 PM, Mike Bayer wrote:
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 
<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 
<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/ <http://www.sqlalchemy.org/>

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See http://stackoverflow.com/help/mcve 
<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
 
<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/ <http://www.sqlalchemy.org/>

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example. See http://stackoverflow.com/help/mcve 
<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+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 <https://groups.google.com/d/msgid/sqlalchemy/1422b5e7-e15f-49ed-894c-9ba718a6f0f3%40www.fastmail.com?utm_medium=email&utm_source=footer>.

--
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/90bb5eae-a20d-228d-a720-78ae07790d7a%40mlb.org.

Reply via email to