-
-
Notifications
You must be signed in to change notification settings - Fork 204
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Description
Sometime on a non-autocommit connection there is a need to run some statements outside a transaction. For example, in psycopg pool:
psycopg/psycopg_pool/psycopg_pool/pool.py
Lines 539 to 546 in 3bce42a
| if conn.autocommit: | |
| conn.execute("") | |
| else: | |
| conn.autocommit = True | |
| try: | |
| conn.execute("") | |
| finally: | |
| conn.autocommit = False |
Maybe we could have a context manager on the connection to disable the transaction behaviour temporarily?
with conn.no_transaction():
conn.execute(query)Entering the block would fail if there is a transaction in progress. The connection would be put in autocommit mode into the block and reset to the original state on exit, even in case of exception. Unlike the transaction() block, there would be no return from the function call.
@asqui what do you think?
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers