2

My doubt is very SQLish but

Since psycopg2 async connections are autocommit, I'm manually setting up transactions defined and then closed in the same cursor/connection.

like this:

async def transaction(self, queries):
    async with aiopg.create_pool(connection) as pool:
        async with pool.acquire() as conn:
            async with conn.cursor() as cur:
                await cur.execute('BEGIN transaction;')
                for query in queries:
                    await cur.execute(query)
                await cur.execute('COMMIT transaction;')

My doubt is since its completly asynchronous, if there is a rollback will other commands that have been processed in the same timespan be also rolledback or will thy be rolled back connection based?

Thanks!!

monobot
  • 109
  • 1
  • 7

1 Answers1

4

The rollback is connection-based.

piro
  • 13,378
  • 5
  • 34
  • 38
  • Thanks piro, I ended using asyncpg because comes with built in transactions that I feel are more secure than manually creating them. – monobot Feb 25 '17 at 22:36