Skip to content

Session Authorization Error #545

@alpaca-attila

Description

@alpaca-attila

Expected behavior

The command returns no error:

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

Actual behavior

Related to this PR #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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions