Determine if a transaction already exists #1644
|
Is there a way to tell when I'm already in a transaction created by the connection context manager while autocommit is set to True? I have a method which starts a transaction using the connection context manager. This method is called by another method which starts a transaction. I want to update my inner method to only start a transaction if it doesn't exist already. To do so the method needs to know if it's in a transaction. All fields I can find appear to be the same before and during the context manager block Output |
Answered by
dvarrazzo
Nov 16, 2023
Replies: 1 comment 2 replies
|
You can use |
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah, you are using
get_transaction_status()which returns the same info.What happens is that the transaction is started but not at the beginning of the block; rather at the first statement, like what happens for a non-autocommit transaction:
I suggest you to move to psycopg 3 which has a more friendly
conn.transaction()block and the behaviour you expect: