Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions databend_sqlalchemy/databend_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1817,8 +1817,7 @@ def get_multi_table_comment(
)

def do_rollback(self, dbapi_connection):
# No transactions
pass
dbapi_connection.rollback()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep automatic lifecycle rollback from raising

With the built-in DBAPI selected by import_dbapi, Connection.rollback() unconditionally raises NotSupportedError (databend_sqlalchemy/connector.py:123-124). SQLAlchemy 1.4/2.x calls dialect.do_rollback() itself during first-connection initialization and for the default pool reset/Connection.close() path, not only for an explicit user rollback, so this delegation makes normal engine.connect()/connection cleanup fail (and can invalidate every returned pool connection) even after a successful query. The dialect needs to keep the unsupported rollback harmless for those lifecycle calls rather than propagate this exception.

Useful? React with 👍 / 👎.


def _check_unicode_returns(self, connection, additional_tests=None):
# We decode everything as UTF-8
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/test_databend_dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
from unittest import mock

import sqlalchemy
import pytest
from conftest import MockCursor, MockDBApi
from pytest import mark
from sqlalchemy.engine import url
from sqlalchemy.sql import text

import databend_sqlalchemy # SQLAlchemy package
from databend_sqlalchemy.errors import NotSupportedError
from databend_sqlalchemy.databend_dialect import (
DatabendCompiler,
DatabendDialect,
Expand Down Expand Up @@ -56,6 +58,22 @@ def test_do_execute(
cursor.execute.reset_mock()
dialect.do_execute(cursor, "SELECT *", (1, 22), None)

def test_do_rollback_propagates_rollback(self, dialect: DatabendDialect):
mock_conn = mock.Mock()
dialect.do_rollback(mock_conn)
mock_conn.rollback.assert_called_once()

def test_do_rollback_raises_not_supported_error(self, dialect: DatabendDialect):
mock_conn = mock.Mock()
mock_conn.rollback.side_effect = NotSupportedError(
"Transactions are not supported"
)
with pytest.raises(
NotSupportedError,
match="Transactions are not supported",
):
dialect.do_rollback(mock_conn)

def test_table_names(
self, dialect: DatabendDialect, connection: mock.Mock(spec=MockDBApi)
):
Expand Down
Loading