Skip to content

Fix zombie queries on metadata#608

Open
viniolivieri wants to merge 2 commits into
trinodb:masterfrom
viniolivieri:master
Open

Fix zombie queries on metadata#608
viniolivieri wants to merge 2 commits into
trinodb:masterfrom
viniolivieri:master

Conversation

@viniolivieri

@viniolivieri viniolivieri commented Jun 16, 2026

Copy link
Copy Markdown

Description

_get_partitions method were leaving zombie queries in Trino with the current implementation.
connection should be closed with or not with context manager usage. The fetch of data here is optionally, but I did implemented because otherwise, query will be consider CANCELLED and not FINISHED.

Non-technical explanation

Fixed zombie queries from partitions metadata queries.

Release notes

( ) This is not user-visible or docs only and no release notes are required.
(x) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

[Queries stuck in FINISHING time](https://github.com/trinodb/trino-python-client/issues/463)
["SEE TABLE SCHEMA" queries to trino remain "FINISHING" when selecting iceberg tables](https://github.com/apache/superset/issues/34992)

@cla-bot

cla-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@cla-bot cla-bot Bot added the cla-signed label Jul 9, 2026
data_types = [desc[1] for desc in res.cursor.description]

if SQLALCHEMY_VERSION >= '2.0.0':
# Lower versions of SQLAlchemy doesn't support execution of query as ctxt man

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then why not always do it like the manual way? the context manager is just syntax sugar AFAIK for the same sequence of operations.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also this path (> 2.0) isn't fetching data anyway so it'll show CANCELLED too.

BTW I don't agree that showing those as CANCELLED is wrong. We are unnecessarily fetching results for cosmetic benefits.

data_types = [desc[1] for desc in res.cursor.description]

if SQLALCHEMY_VERSION >= '2.0.0':
# Lower versions of SQLAlchemy doesn't support execution of query as ctxt man

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also this path (> 2.0) isn't fetching data anyway so it'll show CANCELLED too.

BTW I don't agree that showing those as CANCELLED is wrong. We are unnecessarily fetching results for cosmetic benefits.

partition_names = [desc[0] for desc in conn.cursor.description]
data_types = [desc[1] for desc in conn.cursor.description]
res = conn.fetchall() # Fetching data to consider query as FINISHED and not CANCELED
if not conn.closed:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try ... finally?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix import order and see CI failures

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we avoid mocked tests since the sequence of responses is now hand constructed and doesn't really test anything meaningful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants