From 402b1015a58f0982d5e3f9699297db82d3cdd7b2 Mon Sep 17 00:00:00 2001 From: Astha Mohta <35952883+asthamohta@users.noreply.github.com> Date: Fri, 21 Jul 2023 11:08:09 +0530 Subject: [PATCH] feat: Set LAR True (#940) * changes * tests * Update client.py * Update test_client.py * Update connection.py * setting feature false * changes * set LAR true * Update connection.py * Update client.py * changes * changes --------- Co-authored-by: surbhigarg92 --- 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 | 3 +-- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/google/cloud/spanner_dbapi/connection.py b/google/cloud/spanner_dbapi/connection.py index e6a0610baf..efbdc80f3f 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=False, + route_to_leader_enabled=True, ): """Creates a connection to a Google Cloud Spanner database. @@ -547,10 +547,9 @@ 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 - would route all requests in RW/PDML transactions to the - leader region. + (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. :rtype: :class:`google.cloud.spanner_dbapi.connection.Connection` @@ -568,14 +567,14 @@ def connect( credentials, project=project, client_info=client_info, - route_to_leader_enabled=False, + route_to_leader_enabled=True, ) else: client = spanner.Client( project=project, credentials=credentials, client_info=client_info, - route_to_leader_enabled=False, + route_to_leader_enabled=True, ) 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 c37c5e8411..70bb6310a1 100644 --- a/google/cloud/spanner_v1/client.py +++ b/google/cloud/spanner_v1/client.py @@ -116,10 +116,9 @@ 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 - would route all requests in RW/PDML transactions to the - leader region. + (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. :raises: :class:`ValueError ` if both ``read_only`` and ``admin`` are :data:`True` @@ -139,7 +138,7 @@ def __init__( client_info=_CLIENT_INFO, client_options=None, query_options=None, - route_to_leader_enabled=False, + route_to_leader_enabled=True, ): 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 a5b520bcbf..86dde73159 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=False, + route_to_leader_enabled=True, ) 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=False, + route_to_leader_enabled=True, ) 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 e1532ca470..e67e928203 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=None, + route_to_leader_enabled=True, ): import google.api_core.client_options from google.cloud.spanner_v1 import client as MUT @@ -78,7 +78,6 @@ def _constructor_test_helper( ) else: expected_client_options = client_options - if route_to_leader_enabled is not None: kwargs["route_to_leader_enabled"] = route_to_leader_enabled