trinodb / trinodb/trino-python-client

Session Authorization Error

Open
#545 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
439
Forks
206
PR merge metrics
No merged PRs in 30d

Description

Expected behavior

The command returns no error:

_ = cur.execute("SET SESSION AUTHORIZATION 'username'")
Actual behavior

Related to this PR https://github.com/trinodb/trino-python-client/pull/349
We bumped into some error with the following code

TRINO_HOST='***'
TRINO_USER='***'
TRINO_PASS='***'
TRINO_PORT=443

import logging
from trino.dbapi import connect
from trino.auth import BasicAuthentication

logging.basicConfig(level=logging.ERROR) 

conn = connect(
    host=TRINO_HOST,
    port=TRINO_PORT,
    user=TRINO_USER,
    auth=BasicAuthentication(TRINO_USER, TRINO_PASS),
    http_scheme="https",
)
conn._http_session.verify = False
cur = conn.cursor()
_ = cur.execute("SET SESSION AUTHORIZATION 'username'")
cur.close()
conn.close()

Producing

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): trino.production.lakehouse.tradetalk.us:443
DEBUG:urllib3.connectionpool:https://trino.production.lakehouse.tradetalk.us:443 "POST /v1/statement HTTP/1.1" 200 370
DEBUG:urllib3.connectionpool:[https://trino.production.lakehouse.tradetalk.us:443](https://trino.production.lakehouse.tradetalk.us/) "GET /v1/statement/queued/20250408_205705_36295_5qmnr/y5a9c6452eeb4228649e5bbb1d3008098a8120cdb/1 HTTP/1.1" 200 369
DEBUG:urllib3.connectionpool:https://trino.production.lakehouse.tradetalk.us:443 "GET /v1/statement/queued/20250408_205705_36295_5qmnr/ye59beed6bc2306af1ebc7960d503377c74a095fc/2 HTTP/1.1" 200 819
---------------------------------------------------------------------------
TrinoUserError                            Traceback (most recent call last)
Cell In[195], line 1
----> 1 a = trino_run()

Cell In[193], line 38, in trino_run()
     36 conn._http_session.verify = False
     37 cur = conn.cursor()
---> 38 data = cur.execute("SET SESSION AUTHORIZATION 'dragonfly'")
     39 cur.close()
     40 conn.close()

File ~/git/data-warehouse/venv/lib/python3.9/site-packages/trino/dbapi.py:614, in Cursor.execute(self, operation, params)
    611 else:
    612     self._query = trino.client.TrinoQuery(self._request, query=operation,
    613                                           legacy_primitive_types=self._legacy_primitive_types)
--> 614     self._iterator = iter(self._query.execute())
    615 return self

File ~/git/data-warehouse/venv/lib/python3.9/site-packages/trino/client.py:900, in TrinoQuery.execute(self, additional_http_headers)
    898 # Execute should block until at least one row is received or query is finished or cancelled
    899 while not self.finished and not self.cancelled and len(self._result.rows) == 0:
--> 900     self._result.rows += self.fetch()
    901 return self._result

File ~/git/data-warehouse/venv/lib/python3.9/site-packages/trino/client.py:920, in TrinoQuery.fetch(self)
    918 except requests.exceptions.RequestException as e:
    919     raise trino.exceptions.TrinoConnectionError("failed to fetch: {}".format(e))
--> 920 status = self._request.process(response)
    921 self._update_state(status)
    922 if status.next_uri is None:

File ~/git/data-warehouse/venv/lib/python3.9/site-packages/trino/client.py:689, in TrinoRequest.process(self, http_response)
    687 response = http_response.json()
    688 if "error" in response and response["error"]:
--> 689     raise self._process_error(response["error"], response.get("id"))
    691 if constants.HEADER_CLEAR_SESSION in http_response.headers:
    692     for prop in get_header_values(
    693         http_response.headers, constants.HEADER_CLEAR_SESSION
    694     ):

TrinoUserError: TrinoUserError(type=USER_ERROR, name=NOT_SUPPORTED, message="SET SESSION AUTHORIZATION not supported by client", query_id=20250408_205705_36295_5qmnr)

On trino side:

io.trino.spi.TrinoException: SET SESSION AUTHORIZATION not supported by client
	at io.trino.execution.SetSessionAuthorizationTask.execute(SetSessionAuthorizationTask.java:66)
	at io.trino.execution.SetSessionAuthorizationTask.execute(SetSessionAuthorizationTask.java:38)
	at io.trino.execution.DataDefinitionExecution.start(DataDefinitionExecution.java:152)
	at io.trino.execution.SqlQueryManager.createQuery(SqlQueryManager.java:272)
	at io.trino.dispatcher.LocalDispatchQuery.startExecution(LocalDispatchQuery.java:150)
	at io.trino.dispatcher.LocalDispatchQuery.lambda$waitForMinimumWorkers$2(LocalDispatchQuery.java:134)
	at io.airlift.concurrent.MoreFutures.lambda$addSuccessCallback$12(MoreFutures.java:570)
	at io.airlift.concurrent.MoreFutures$3.onSuccess(MoreFutures.java:545)
	at com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:1139)
	at io.trino.$gen.Trino_472____20250408_102234_2.run(Unknown Source)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1575)

However, setting the user authorization from DBevear works perfectly fine.
Maybe some parameters are not sent to Trino in the http request?

Steps To Reproduce

Trino python client:
trino 0.333.0
Trino cluster (version 472)

Log output

No response

Operating System

Apple M3 Pro MacOS 15.3.2

Trino Python client version

0.333.0

Trino Server version

472

Python version

Python 3.9.6

Are you willing to submit PR?
  • Yes I am willing to submit a PR!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the SET SESSION AUTHORIZATION failure with the versions given, then read Cursor.execute in trino/dbapi.py and TrinoQuery.execute, fetch, and TrinoRequest.process in trino/client.py. Compare the request behavior with the related PR #349. Done means the command succeeds against Trino 472 without breaking ordinary query execution.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.