trino-python-client icon indicating copy to clipboard operation
trino-python-client copied to clipboard

Add defer_connect config to allow eagerly verifying connection

Open Shaheer-rossoneri14 opened this issue 11 months ago • 8 comments

Description

Add defer_connect config to allow eagerly verifying connection.

Depends on #393.

Non-technical explanation

This commit adds a new connection parameter defer_connect which can be set to False to force creating a connection when trino.dbapi.connect is called. Any connection errors as a result of that get rewrapped into trino.exceptions.TrinoConnectionError.

This doesn't end up actually executing a query on the server because after the initial POST request the nextUri in the response is not followed which leaves the query in QUEUED state. This is not documented in the Trino REST API but the server does behave like this today. The benefit is that we can very cheaply verify if the connection is valid without polluting the server's query history or adding queries to queue.

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:

* Fix some things. ({issue}`issuenumber`)

Shaheer-rossoneri14 avatar Jul 18 '23 18:07 Shaheer-rossoneri14

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 [email protected]. 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[bot] avatar Jul 18 '23 18:07 cla-bot[bot]

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 [email protected]. 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[bot] avatar Jul 18 '23 18:07 cla-bot[bot]

Please drop https://github.com/trinodb/trino-python-client/pull/394/commits/9d417d60c85eac7534f3d2b743da1ee976d74e70 from here since it's being added here https://github.com/trinodb/trino-python-client/pull/393

hovaesco avatar Jul 23 '23 14:07 hovaesco

@hovaesco Dropped the commit https://github.com/trinodb/trino-python-client/commit/9d417d60c85eac7534f3d2b743da1ee976d74e70.

Shaheer-rossoneri14 avatar Aug 06 '23 15:08 Shaheer-rossoneri14

This is useful since I've heard often that people complain that they don't know the credentials are wrong or that the server isn't running AFTER issuing the first query. However only PyMySql client seems to use the defer_connect arg.

hashhar avatar Aug 17 '23 05:08 hashhar

@ebyhr @mdesmet @hovaesco what are your opinions? I like this because it's a relatively small change and addresses a complaint I've heard quite often. The downside is there are already enough parameters for the connect method.

hashhar avatar Aug 17 '23 05:08 hashhar

It looks like a useful change from my perspective, note that PyMySql sets defer_connect to False by default.

hovaesco avatar Aug 17 '23 08:08 hovaesco

Please rebase on master.

hovaesco avatar Aug 31 '23 08:08 hovaesco