question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

possible bug in start_transaction (dbapi.py)

See original GitHub issue

Issue:

start_transaction() (dbapi.py) might need to set the isolation level properly.

Details:

Currently the start_transaction does not change the isolation level (#b), while cursor() only compare the isolation level with AUTO_COMMIT(#a). The result is that the transaction and the query uses different request instance and run independently (perhaps)

For some application (likes dbt), the following sequence is heavily used:

1. start_transaction()
2. query
3. commit() or rollback()

If the query finishes within the transaction-timeout, everything looks fine. If the query succeed but took a longer time than transaction-timeout (default is 5 min), error will happen at 3 likes below. Note that in this case, the query succeed and the result is recorded (because it seems to run with auto_commit enabled sessions)

trino.exceptions.DatabaseError: failed to commit transaction 73dc7443-ec53-4911-95be-a372792743b4: TrinoUserError(type=USER_ERROR, name=UNKNOWN_TRANSACTION, message="Unknown transaction ID: 73dc7443-ec53-4911-95be-a372792743b4. Possibly expired? Commands ignored until end of transaction block", query_id=20211121_145311_00013_7rttf)

Expectation:

It might depend on the spec or definition of transaction-timeout, but expectation is that there is no error in the above mentioned case.

Suggested solution:

Maybe start_transaction should have the option to set isolation level (with REPEATABLE_READ as default). And commit()/rollback() need to set the isolation level back to the value it is set when connection is initialized.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
hashharcommented, Dec 7, 2021

IIUC, It’s more about reusing the same transaction request instance in start_transaction() and commit/rollback().

Correct. From my understanding there are two issues here:

  1. Looks like we don’t handle the case when connection is in auto-commit and the user explicitly manages their own transaction. The cause seems because we don’t disable auto-commit when the cursor creates a transaction. See for reference Postgres driver - https://github.com/tlocke/pg8000/blob/a83e85b4a3493efe4a53fdbe142d53306c1f5622/pg8000/dbapi.py#L448-L449. And psycopg2 for example starts implicit transactions if connection isn’t in autocommit.

  2. transactions are broken in the client since we aren’t managing the lifecycle of the request attached to a transaction correctly.

1reaction
hovaescocommented, Dec 8, 2021

Thanks @hashhar and @bachng2017 for the explanation. I’m starting to work to address this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

execute("begin immediate") throwing OperationalError
So, I would say this is "not a bug" in Python, ... There are already a few test's that start a transaction explicitly:...
Read more >
Bug #838581 “Failures in db_pool code: 'NoneType' object ...
The "'NoneType' object has no attribute '_keymap'" exception is most likely caused by a bug in SQLAlchemy that has been fixed for a...
Read more >
tlocke/pg8000: A Pure-Python PostgreSQL Driver - GitHub
There is a longstanding bug in the PostgreSQL server whereby if a COMMIT is issued against a failed transaction, the transaction is silently...
Read more >
MySQL Connector/Python Release Notes
Connector/Python now implements the authentication_kerberos_client plugin to support Kerberos authentication for classic MySQL protocol connections. Bugs Fixed.
Read more >
Usage Guide — FDB 2.0.2 documentation
Python DB API 2.0 assume that if database engine supports transactions, ... If this is not possible due to the specified number of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found