Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with transaction #66

Closed
chemiron opened this issue Jul 15, 2015 · 2 comments
Closed

Problem with transaction #66

chemiron opened this issue Jul 15, 2015 · 2 comments

Comments

@chemiron
Copy link

Hi,
I've got a problem with aiopg when using transaction. I've used a simple code for transaction:

trans = yield from conn.begin()
try:
      yield from fn(self, conn, *args, **kwargs)
except:
      yield from trans.rollback()
      raise
else:
      yield from trans.commit()

But if there timeout is occurred I'll get the next traceback:

Traceback (most recent call last):
...
File "/home/alex/work/python/.envs/stload3/lib/python3.4/site-packages/aiopg/sa/connection.py", line 100, in execute
yield from cursor.execute(str(compiled), post_processed_params[0])
File "/home/alex/work/python/.envs/stload3/lib/python3.4/site-packages/aiopg/cursor.py", line 112, in execute
yield from self._conn._poll(waiter, timeout)
File "/home/alex/work/python/.envs/stload3/lib/python3.4/site-packages/aiopg/connection.py", line 162, in _poll
yield from asyncio.wait_for(self._waiter, timeout, loop=self._loop)
File "/usr/lib/python3.4/asyncio/tasks.py", line 381, in wait_for
raise futures.TimeoutError()
concurrent.futures._base.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/alex/work/python/.envs/stload3/lib/python3.4/site-packages/aiopg/sa/connection.py", line 185, in _rollback_impl
yield from cur.execute('ROLLBACK')
File "/home/alex/work/python/.envs/stload3/lib/python3.4/site-packages/aiopg/cursor.py", line 107, in execute
self._impl.execute(operation, parameters)
psycopg2.ProgrammingError: execute cannot be used while an asynchronous query is underway

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
...
File "/home/alex/work/python/.envs/stload3/lib/python3.4/site-packages/aiopg/sa/transaction.py", line 67, in rollback
yield from self._do_rollback()
File "/home/alex/work/python/.envs/stload3/lib/python3.4/site-packages/aiopg/sa/transaction.py", line 95, in _do_rollback
yield from self._connection._rollback_impl()
File "/home/alex/work/python/.envs/stload3/lib/python3.4/site-packages/aiopg/sa/connection.py", line 187, in _rollback_impl
cur.close()
File "/home/alex/work/python/.envs/stload3/lib/python3.4/site-packages/aiopg/cursor.py", line 49, in close
self._impl.close()
psycopg2.ProgrammingError: close cannot be used while an asynchronous query is underway

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
...
File "/home/alex/work/python/.envs/stload3/lib/python3.4/site-packages/aiopg/sa/engine.py", line 190, in exit
self._engine.release(self._conn)
File "/home/alex/work/python/.envs/stload3/lib/python3.4/site-packages/aiopg/sa/engine.py", line 133, in release
raise InvalidRequestError("Cannot release a connection with "
aiopg.sa.exc.InvalidRequestError: Cannot release a connection with not finished transaction

As I think if we get TimoutError while the query executing, the query should be cancelled.
Thanks

@asvetlov
Copy link
Member

Thanks for report

@asvetlov
Copy link
Member

Fixed by 8ca948e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants