I am developing an app together with a partner. I do the database part (PostgreSQL), my partner implements the app on the web-server with python using SQLAlchemy. We make heavy use of stored procedures. A SELECT
query on one of those looks like this in the db log:
SET TRANSACTION ISOLATION LEVEL READ COMMITTED;
SELECT col_a, col_b FROM f_stored_proc(E'myvalue');
ROLLBACK;
In the stored procedures I write certain input to a log table. The app queries by SELECT
, SQLAlchemy only sees a SELECT statement and insists on a ROLLBACK
. Logging fails. I need it to COMMIT
instead. My partner claims there is no easy way, we would have to remove SQLAlchemy altogether. I think he must be wrong but lack the konwledge to claim otherwise.
Is there an easy way to make SQLAlchemy COMMIT
instead of ROLLBACK
?
What keeps me from just executing trans.commit()
? Do I need to set autoflush=False
for that?
I have scanned the FAQ, but did not find an answer there.
Searching SO revealed some related questions like here and here, but I am not in the clear.
Maybe this recipe would work?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…