Determine transaction after_flush state

16 views
Skip to first unread message

Val Huber

unread,
Jan 11, 2023, 7:44:08 PM1/11/23
to sqlalchemy
In API Logic Server, clients can make RESTful requests that cause SQLAlchemy reads.  These are subjected to authorization security using do_orm_execute (which is amazing, by the way).  These add filters to ensure proper access.  This is all fine.

But, when the client makes changes, these activate business logic, which needs to run without auth security.

My question is: how can my do_orm_execute event handler determine we are in/after after-flush state?  Sorry if I missed them, but I did not find variables method on session or transaction for this.

Thanks in advance,
Val

Mike Bayer

unread,
Jan 11, 2023, 9:23:01 PM1/11/23
to noreply-spamdigest via sqlalchemy

a session can flush any number of times, so what here determines "after" flush state as far as do_orm_execute()? do_orm_execute is not called within the flush itself (well, maybe it is...)

If you see do_orm_executes inside of the flush, I guess you could look at session._flushing, is that what you are looking for ?
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
 
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+...@googlegroups.com.

Val Huber

unread,
Jan 11, 2023, 9:28:09 PM1/11/23
to sqlal...@googlegroups.com
Sounds like session._flushing is exactly what I want… presuming it means “I have started flushing, in fact may have flushed any number of times”.

Thanks for the again-quick response, if my presumption is correct, I am all set.

Regards,
Val

You received this message because you are subscribed to a topic in the Google Groups "sqlalchemy" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sqlalchemy/kO4zI2r6k0c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sqlalchemy+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/d864d888-a058-403b-b25b-315cb16d3158%40app.fastmail.com.

Mike Bayer

unread,
Jan 12, 2023, 9:34:52 AM1/12/23
to noreply-spamdigest via sqlalchemy
it means the Session is in the middle of the "flush()" method.  it's a boolean state.  when flush() is over, it turns back off.
Reply all
Reply to author
Forward
0 new messages