Skip to content

Commit 78a0ff6

Browse files
authored
Merge branch 'main' into fix-broken-link
2 parents 6654777 + 1f4e98c commit 78a0ff6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2911
-467
lines changed

.github/workflows/mock_server_tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
pull_request:
66
name: Run Spanner tests against an in-mem mock server
77
jobs:
8-
system-tests:
8+
mock-server-tests:
99
runs-on: ubuntu-latest
1010

1111
steps:

.github/workflows/presubmit.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
pull_request:
6+
name: Presubmit checks
7+
permissions:
8+
contents: read
9+
pull-requests: write
10+
jobs:
11+
lint:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
- name: Setup Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: 3.8
21+
- name: Install nox
22+
run: python -m pip install nox
23+
- name: Check formatting
24+
run: nox -s lint
25+
units:
26+
runs-on: ubuntu-latest
27+
strategy:
28+
fail-fast: false
29+
matrix:
30+
python: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
31+
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v4
35+
- name: Setup Python
36+
uses: actions/setup-python@v5
37+
with:
38+
python-version: ${{matrix.python}}
39+
- name: Install nox
40+
run: python -m pip install nox
41+
- name: Run unit tests
42+
run: nox -s unit-${{matrix.python}}

.kokoro/presubmit/presubmit.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Format: //devtools/kokoro/config/proto/build.proto
22

3-
# Disable system tests.
3+
# Only run a subset of all nox sessions
44
env_vars: {
5-
key: "RUN_SYSTEM_TESTS"
6-
value: "false"
5+
key: "NOX_SESSION"
6+
value: "unit-3.8 unit-3.12 cover docs docfx"
77
}

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "3.53.0"
2+
".": "3.54.0"
33
}

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@
44

55
[1]: https://pypi.org/project/google-cloud-spanner/#history
66

7+
## [3.54.0](https://github.com/googleapis/python-spanner/compare/v3.53.0...v3.54.0) (2025-04-28)
8+
9+
10+
### Features
11+
12+
* Add interval type support ([#1340](https://github.com/googleapis/python-spanner/issues/1340)) ([6ca9b43](https://github.com/googleapis/python-spanner/commit/6ca9b43c3038eca1317c7c9b7e3543b5f1bc68ad))
13+
* Add sample for pre-split feature ([#1333](https://github.com/googleapis/python-spanner/issues/1333)) ([ca76108](https://github.com/googleapis/python-spanner/commit/ca76108809174e4f3eea38d7ac2463d9b4c73304))
14+
* Add SQL statement for begin transaction isolation level ([#1331](https://github.com/googleapis/python-spanner/issues/1331)) ([3ac0f91](https://github.com/googleapis/python-spanner/commit/3ac0f9131b38e5cfb2b574d3d73b03736b871712))
15+
* Support transaction isolation level in dbapi ([#1327](https://github.com/googleapis/python-spanner/issues/1327)) ([03400c4](https://github.com/googleapis/python-spanner/commit/03400c40f1c1cc73e51733f2a28910a8dd78e7d9))
16+
17+
18+
### Bug Fixes
19+
20+
* Improve client-side regex statement parser ([#1328](https://github.com/googleapis/python-spanner/issues/1328)) ([b3c259d](https://github.com/googleapis/python-spanner/commit/b3c259deec817812fd8e4940faacf4a927d0d69c))
21+
722
## [3.53.0](https://github.com/googleapis/python-spanner/compare/v3.52.0...v3.53.0) (2025-03-12)
823

924

README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,13 @@ Connection API represents a wrap-around for Python Spanner API, written in accor
252252
result = cursor.fetchall()
253253
254254
255+
If using [fine-grained access controls](https://cloud.google.com/spanner/docs/access-with-fgac) you can pass a ``database_role`` argument to connect as that role:
256+
257+
.. code:: python
258+
259+
connection = connect("instance-id", "database-id", database_role='your-role')
260+
261+
255262
Aborted Transactions Retry Mechanism
256263
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
257264

google/cloud/spanner_admin_database_v1/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "3.53.0" # {x-release-please-version}
16+
__version__ = "3.54.0" # {x-release-please-version}

google/cloud/spanner_admin_instance_v1/gapic_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
__version__ = "3.53.0" # {x-release-please-version}
16+
__version__ = "3.54.0" # {x-release-please-version}

google/cloud/spanner_dbapi/connection.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
from google.api_core.exceptions import Aborted
1919
from google.api_core.gapic_v1.client_info import ClientInfo
20+
from google.auth.credentials import AnonymousCredentials
21+
2022
from google.cloud import spanner_v1 as spanner
2123
from google.cloud.spanner_dbapi import partition_helper
2224
from google.cloud.spanner_dbapi.batch_dml_executor import BatchMode, BatchDmlExecutor
@@ -720,6 +722,7 @@ def connect(
720722
user_agent=None,
721723
client=None,
722724
route_to_leader_enabled=True,
725+
database_role=None,
723726
**kwargs,
724727
):
725728
"""Creates a connection to a Google Cloud Spanner database.
@@ -763,6 +766,10 @@ def connect(
763766
disable leader aware routing. Disabling leader aware routing would
764767
route all requests in RW/PDML transactions to the closest region.
765768
769+
:type database_role: str
770+
:param database_role: (Optional) The database role to connect as when using
771+
fine-grained access controls.
772+
766773
**kwargs: Initial value for connection variables.
767774
768775
@@ -784,11 +791,15 @@ def connect(
784791
route_to_leader_enabled=route_to_leader_enabled,
785792
)
786793
else:
794+
client_options = None
795+
if isinstance(credentials, AnonymousCredentials):
796+
client_options = kwargs.get("client_options")
787797
client = spanner.Client(
788798
project=project,
789799
credentials=credentials,
790800
client_info=client_info,
791801
route_to_leader_enabled=route_to_leader_enabled,
802+
client_options=client_options,
792803
)
793804
else:
794805
if project is not None and client.project != project:
@@ -797,8 +808,10 @@ def connect(
797808
instance = client.instance(instance_id)
798809
database = None
799810
if database_id:
800-
database = instance.database(database_id, pool=pool)
801-
conn = Connection(instance, database)
811+
database = instance.database(
812+
database_id, pool=pool, database_role=database_role
813+
)
814+
conn = Connection(instance, database, **kwargs)
802815
if pool is not None:
803816
conn._own_pool = False
804817

google/cloud/spanner_dbapi/transaction_helper.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def add_execute_statement_for_retry(
162162
self._last_statement_details_per_cursor[cursor] = last_statement_result_details
163163
self._statement_result_details_list.append(last_statement_result_details)
164164

165-
def retry_transaction(self):
165+
def retry_transaction(self, default_retry_delay=None):
166166
"""Retry the aborted transaction.
167167
168168
All the statements executed in the original transaction
@@ -202,7 +202,9 @@ def retry_transaction(self):
202202
raise RetryAborted(RETRY_ABORTED_ERROR, ex)
203203
return
204204
except Aborted as ex:
205-
delay = _get_retry_delay(ex.errors[0], attempt)
205+
delay = _get_retry_delay(
206+
ex.errors[0], attempt, default_retry_delay=default_retry_delay
207+
)
206208
if delay:
207209
time.sleep(delay)
208210

0 commit comments

Comments
 (0)