Skip to content

Commit 5cf68f4

Browse files
committed
Fix issue of queries not reaching completed state
1 parent e260273 commit 5cf68f4

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

tests/integration/test_sqlalchemy_integration.py

+17
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1010
# See the License for the specific language governing permissions and
1111
# limitations under the License
12+
import os
1213
import pytest
1314
import sqlalchemy as sqla
1415
from sqlalchemy.sql import and_, or_, not_
@@ -177,6 +178,22 @@ def test_conjunctions(trino_connection):
177178
assert len(rows) == 1
178179

179180

181+
@pytest.mark.parametrize('trino_connection', ['system'], indirect=True)
182+
def test_completed_states(trino_connection):
183+
_, conn = trino_connection
184+
metadata = sqla.MetaData()
185+
queries = sqla.Table('queries', metadata, schema='runtime', autoload_with=conn)
186+
s = sqla.select(queries.c.state).where(queries.c.query == "SELECT version()")
187+
result = conn.execute(s)
188+
rows = result.fetchall()
189+
assert len(rows) > 0
190+
for row in rows:
191+
if os.environ.get("TRINO_VERSION") == '351':
192+
assert row['state'] == 'FAILED'
193+
else:
194+
assert row['state'] == 'FINISHED'
195+
196+
180197
@pytest.mark.parametrize('trino_connection', ['tpch'], indirect=True)
181198
def test_textual_sql(trino_connection):
182199
_, conn = trino_connection

trino/sqlalchemy/dialect.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def _get_server_version_info(self, connection: Connection) -> Any:
317317
query = "SELECT version()"
318318
try:
319319
res = connection.execute(sql.text(query))
320-
version = res.scalar()
320+
version = res.scalar_one()
321321
return tuple([version])
322322
except exc.ProgrammingError as e:
323323
logger.debug(f"Failed to get server version: {e.orig.message}")

0 commit comments

Comments
 (0)