From 40520c51e1f0ca0c1e2480c5567e5305a90a07f7 Mon Sep 17 00:00:00 2001 From: surbhigarg92 Date: Fri, 21 Jul 2023 22:38:58 +0530 Subject: [PATCH 1/3] feat: Set LAR as False --- google/cloud/spanner_dbapi/connection.py | 13 +++++++------ google/cloud/spanner_v1/client.py | 9 +++++---- tests/unit/spanner_dbapi/test_connect.py | 4 ++-- tests/unit/test_client.py | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/google/cloud/spanner_dbapi/connection.py b/google/cloud/spanner_dbapi/connection.py index efbdc80f3f..e6a0610baf 100644 --- a/google/cloud/spanner_dbapi/connection.py +++ b/google/cloud/spanner_dbapi/connection.py @@ -508,7 +508,7 @@ def connect( pool=None, user_agent=None, client=None, - route_to_leader_enabled=True, + route_to_leader_enabled=False, ): """Creates a connection to a Google Cloud Spanner database. @@ -547,9 +547,10 @@ def connect( :type route_to_leader_enabled: boolean :param route_to_leader_enabled: - (Optional) Default True. Set route_to_leader_enabled as False to - disable leader aware routing. Disabling leader aware routing would - route all requests in RW/PDML transactions to the closest region. + (Optional) Default False. Set route_to_leader_enabled as True to + Enable leader aware routing. Enabling leader aware routing + would route all requests in RW/PDML transactions to the + leader region. :rtype: :class:`google.cloud.spanner_dbapi.connection.Connection` @@ -567,14 +568,14 @@ def connect( credentials, project=project, client_info=client_info, - route_to_leader_enabled=True, + route_to_leader_enabled=False, ) else: client = spanner.Client( project=project, credentials=credentials, client_info=client_info, - route_to_leader_enabled=True, + route_to_leader_enabled=False, ) else: if project is not None and client.project != project: diff --git a/google/cloud/spanner_v1/client.py b/google/cloud/spanner_v1/client.py index 70bb6310a1..c37c5e8411 100644 --- a/google/cloud/spanner_v1/client.py +++ b/google/cloud/spanner_v1/client.py @@ -116,9 +116,10 @@ class Client(ClientWithProject): :type route_to_leader_enabled: boolean :param route_to_leader_enabled: - (Optional) Default True. Set route_to_leader_enabled as False to - disable leader aware routing. Disabling leader aware routing would - route all requests in RW/PDML transactions to the closest region. + (Optional) Default False. Set route_to_leader_enabled as True to + Enable leader aware routing. Enabling leader aware routing + would route all requests in RW/PDML transactions to the + leader region. :raises: :class:`ValueError ` if both ``read_only`` and ``admin`` are :data:`True` @@ -138,7 +139,7 @@ def __init__( client_info=_CLIENT_INFO, client_options=None, query_options=None, - route_to_leader_enabled=True, + route_to_leader_enabled=False, ): self._emulator_host = _get_spanner_emulator_host() diff --git a/tests/unit/spanner_dbapi/test_connect.py b/tests/unit/spanner_dbapi/test_connect.py index 86dde73159..a5b520bcbf 100644 --- a/tests/unit/spanner_dbapi/test_connect.py +++ b/tests/unit/spanner_dbapi/test_connect.py @@ -86,7 +86,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) @@ -120,7 +120,7 @@ def test_w_credential_file_path(self, mock_client): credentials_path, project=PROJECT, client_info=mock.ANY, - route_to_leader_enabled=True, + route_to_leader_enabled=False, ) client_info = factory.call_args_list[0][1]["client_info"] self.assertEqual(client_info.user_agent, USER_AGENT) diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py index e67e928203..f8bcb709cb 100644 --- a/tests/unit/test_client.py +++ b/tests/unit/test_client.py @@ -59,7 +59,7 @@ def _constructor_test_helper( client_options=None, query_options=None, expected_query_options=None, - route_to_leader_enabled=True, + route_to_leader_enabled=None, ): import google.api_core.client_options from google.cloud.spanner_v1 import client as MUT From f118fa043bf80b400aba255d51edf75910e8f145 Mon Sep 17 00:00:00 2001 From: surbhigarg92 Date: Fri, 21 Jul 2023 22:47:04 +0530 Subject: [PATCH 2/3] Update google/cloud/spanner_dbapi/connection.py Co-authored-by: Rajat Bhatta <93644539+rajatbhatta@users.noreply.github.com> --- google/cloud/spanner_dbapi/connection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/cloud/spanner_dbapi/connection.py b/google/cloud/spanner_dbapi/connection.py index e6a0610baf..6f5a9a4e0c 100644 --- a/google/cloud/spanner_dbapi/connection.py +++ b/google/cloud/spanner_dbapi/connection.py @@ -548,7 +548,7 @@ def connect( :type route_to_leader_enabled: boolean :param route_to_leader_enabled: (Optional) Default False. Set route_to_leader_enabled as True to - Enable leader aware routing. Enabling leader aware routing + enable leader aware routing. Enabling leader aware routing would route all requests in RW/PDML transactions to the leader region. From 244ef7b57ce1a8aeff1fad037b9bdd064f1cebd8 Mon Sep 17 00:00:00 2001 From: surbhigarg92 Date: Fri, 21 Jul 2023 22:47:10 +0530 Subject: [PATCH 3/3] Update google/cloud/spanner_v1/client.py Co-authored-by: Rajat Bhatta <93644539+rajatbhatta@users.noreply.github.com> --- google/cloud/spanner_v1/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google/cloud/spanner_v1/client.py b/google/cloud/spanner_v1/client.py index c37c5e8411..955fd94820 100644 --- a/google/cloud/spanner_v1/client.py +++ b/google/cloud/spanner_v1/client.py @@ -117,7 +117,7 @@ class Client(ClientWithProject): :type route_to_leader_enabled: boolean :param route_to_leader_enabled: (Optional) Default False. Set route_to_leader_enabled as True to - Enable leader aware routing. Enabling leader aware routing + enable leader aware routing. Enabling leader aware routing would route all requests in RW/PDML transactions to the leader region.