Skip to content

Commit

Permalink
fix: pass through route-to-leader option in dbapi
Browse files Browse the repository at this point in the history
The route-to-leader option given to the dbapi connection was not passed
on to the actual Spanner client.
  • Loading branch information
olavloite committed Nov 4, 2024
1 parent e15e84f commit fa8e006
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions google/cloud/spanner_dbapi/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,14 +712,14 @@ def connect(
credentials,
project=project,
client_info=client_info,
route_to_leader_enabled=True,
route_to_leader_enabled=route_to_leader_enabled,
)
else:
client = spanner.Client(
project=project,
credentials=credentials,
client_info=client_info,
route_to_leader_enabled=True,
route_to_leader_enabled=route_to_leader_enabled,
)
else:
if project is not None and client.project != project:
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/spanner_dbapi/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def test_w_implicit(self, mock_client):

self.assertIs(connection.instance, instance)
client.instance.assert_called_once_with(INSTANCE)
mock_client.assert_called_once_with(
project=mock.ANY,
credentials=mock.ANY,
client_info=mock.ANY,
route_to_leader_enabled=True,
)

self.assertIs(connection.database, database)
instance.database.assert_called_once_with(DATABASE, pool=None)
Expand Down Expand Up @@ -86,7 +92,7 @@ def test_w_explicit(self, mock_client):
project=PROJECT,
credentials=credentials,
client_info=mock.ANY,
route_to_leader_enabled=True,
route_to_leader_enabled=False,
)
client_info = mock_client.call_args_list[0][1]["client_info"]
self.assertEqual(client_info.user_agent, USER_AGENT)
Expand Down

0 comments on commit fa8e006

Please sign in to comment.