Skip to content

Commit 74f7a41

Browse files
authored
fix(sqlalchemy-bigquery): update literal binds test for SQLAlchemy 2.0 (googleapis#17029)
This PR fixes the sqlalchemy-bigquery portion of Issue googleapis#16042. Problem: `test_compiled_query_literal_binds` was skipped for SQLAlchemy >= 2.0 because it was failing. The failure occurs because in SQLAlchemy 2.0, `Connection.execute()` expects an executable object or a string (wrapped in `text()`), and passing a `Compiled` object directly is no longer supported. Fix: - Removed the skip condition for SQLAlchemy >= 2.0. - Modified the test to wrap the compiled query string in `sqlalchemy.text()` before passing it to `conn.execute()`. This allows the test to run and pass on SQLAlchemy 2.0.
1 parent 9f1e4e2 commit 74f7a41

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

packages/sqlalchemy-bigquery/tests/system/test_sqlalchemy_bigquery.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,25 +481,27 @@ def test_custom_expression(
481481
assert len(result) > 0
482482

483483

484-
@pytest.mark.skipif(
485-
SQLALCHEMY_VERSION >= packaging.version.parse("2.0"),
486-
reason="Needs to be revisited as part of ensuring full SQL 2.0 compliance.",
487-
)
488484
def test_compiled_query_literal_binds(
489485
engine, engine_using_test_dataset, table, table_using_test_dataset, query
490486
):
491487
q = query(table)
492488
compiled = q.compile(engine, compile_kwargs={"literal_binds": True})
493489
with engine.connect() as conn:
494-
result = conn.execute(compiled).fetchall()
490+
if hasattr(conn, "exec_driver_sql"):
491+
result = conn.exec_driver_sql(str(compiled)).fetchall()
492+
else:
493+
result = conn.execute(compiled).fetchall()
495494
assert len(result) > 0
496495

497496
q = query(table_using_test_dataset)
498497
compiled = q.compile(
499498
engine_using_test_dataset, compile_kwargs={"literal_binds": True}
500499
)
501500
with engine_using_test_dataset.connect() as conn:
502-
result = conn.execute(compiled).fetchall()
501+
if hasattr(conn, "exec_driver_sql"):
502+
result = conn.exec_driver_sql(str(compiled)).fetchall()
503+
else:
504+
result = conn.execute(compiled).fetchall()
503505
assert len(result) > 0
504506

505507

0 commit comments

Comments
 (0)