Skip to content

SQLAlchemy connection does not work after latest release #556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task
sharas2050 opened this issue May 9, 2025 · 5 comments · May be fixed by #564
Open
1 task

SQLAlchemy connection does not work after latest release #556

sharas2050 opened this issue May 9, 2025 · 5 comments · May be fixed by #564
Assignees

Comments

@sharas2050
Copy link

Expected behavior

connection engine connects successfully

engine = create_engine('trino://user:[email protected]:443/data')
connection = engine.connect()

Actual behavior

Following code snippet returns error

engine = create_engine('trino://user:[email protected]:443/data')
connection = engine.connect()

rows = connection.execute(text("SELECT * FROM data.schema.table limit 5"))

print(rows.fetchall())

PRODUCES:
Traceback (most recent call last):

  File "/git/trino-python-client/main.py", line 19, in <module>
    rows = connection.execute(text("SELECT * FROM data.schema.table limit 5"))
  File "/Library/Caches/pypoetry/virtualenvs/trino-client-TtW9DZEh-py3.13/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 1416, in execute
    return meth(
        self,
        distilled_parameters,
        execution_options or NO_OPTIONS,
    )
  File "/Library/Caches/pypoetry/virtualenvs/trino-client-TtW9DZEh-py3.13/lib/python3.13/site-packages/sqlalchemy/sql/elements.py", line 523, in _execute_on_connection
    return connection._execute_clauseelement(
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        self, distilled_params, execution_options
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Library/Caches/pypoetry/virtualenvs/trino-client-TtW9DZEh-py3.13/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 1638, in _execute_clauseelement
    ret = self._execute_context(
        dialect,
    ...<8 lines>...
        cache_hit=cache_hit,
    )
  File "/Library/Caches/pypoetry/virtualenvs/trino-client-TtW9DZEh-py3.13/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 1843, in _execute_context
    return self._exec_single_context(
           ~~~~~~~~~~~~~~~~~~~~~~~~~^
        dialect, context, statement, parameters
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Library/Caches/pypoetry/virtualenvs/trino-client-TtW9DZEh-py3.13/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 1983, in _exec_single_context
    self._handle_dbapi_exception(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        e, str_statement, effective_parameters, cursor, context
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Library/Caches/pypoetry/virtualenvs/trino-client-TtW9DZEh-py3.13/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 2355, in _handle_dbapi_exception
    raise exc_info[1].with_traceback(exc_info[2])
  File "/Library/Caches/pypoetry/virtualenvs/trino-client-TtW9DZEh-py3.13/lib/python3.13/site-packages/sqlalchemy/engine/base.py", line 1964, in _exec_single_context
    self.dialect.do_execute(
    ~~~~~~~~~~~~~~~~~~~~~~~^
        cursor, str_statement, effective_parameters, context
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Library/Caches/pypoetry/virtualenvs/trino-client-TtW9DZEh-py3.13/lib/python3.13/site-packages/trino/sqlalchemy/dialect.py", line 442, in do_execute
    cursor.execute(statement, parameters)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Caches/pypoetry/virtualenvs/trino-client-TtW9DZEh-py3.13/lib/python3.13/site-packages/trino/dbapi.py", line 629, in execute
    self._iterator = iter(self._query.execute())
                          ~~~~~~~~~~~~~~~~~~~^^
  File "/Library/Caches/pypoetry/virtualenvs/trino-client-TtW9DZEh-py3.13/lib/python3.13/site-packages/trino/client.py", line 886, in execute
    status = self._request.process(response)
  File "/Library/Caches/pypoetry/virtualenvs/trino-client-TtW9DZEh-py3.13/lib/python3.13/site-packages/trino/client.py", line 684, in process
    self.raise_response_error(http_response)
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/Library/Caches/pypoetry/virtualenvs/trino-client-TtW9DZEh-py3.13/lib/python3.13/site-packages/trino/client.py", line 675, in raise_response_error
    raise exceptions.HttpError(
    ...<4 lines>...
    )
trino.exceptions.HttpError: error 404: b'404 page not found\n'

Steps To Reproduce

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

Log output

No response

Operating System

macOS Sequoia Version 15.1

Trino Python client version

0.334.0

Trino Server version

472

Python version

Python 3.13.2

Are you willing to submit PR?

  • Yes I am willing to submit a PR!
@damian3031 damian3031 self-assigned this May 21, 2025
@damian3031
Copy link
Member

Hi @sharas2050, could you check if explicitly setting http_scheme to https solves your issue?

engine = create_engine(
    'trino://user:[email protected]:443/data',
    connect_args = {
        "http_scheme": "https",
    }
)

@sharas2050
Copy link
Author

Hi, yes. Adding connection args solved the issue. Thanks

@damian3031
Copy link
Member

I think that TPC should automatically set the correct HTTP scheme if a port is explicitly provided.
@hashhar WDYT?
I can open PR for that

@hashhar
Copy link
Member

hashhar commented May 27, 2025

Port 443 is not guaranteed to be HTTPS. It's just a convention.

So we can auto-set schema to HTTPS for 443 and HTTP for 80 and leave empty for others BUT IF AND ONLY IF http_scheme was not explicitly provided.

Please go ahead @damian3031

@hashhar
Copy link
Member

hashhar commented May 29, 2025

Is this same issue as #557?

@damian3031 damian3031 linked a pull request Jun 4, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants