GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — chore: add samples for transaction timeout configuration by alkatrivedi · Pull Request #1380 · googleapis/python-spanner

This repository was archived by the owner on Jun 8, 2026. It is now read-only.

chore: add samples for transaction timeout configuration #1380

Merged
surbhigarg92 merged 1 commit into googleapis:main from alkatrivedi:transaction-with-timeout
May 27, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

chore: add samples for transaction timeout configuration #1380

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
9a61d78
chore: add samples for transaction timeout configuration
alkatrivedi May 23, 2025
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

36 changes: 36 additions & 0 deletions 36 samples/samples/snippets.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2510,6 +2510,36 @@ def update_venues(transaction):
# [END spanner_set_transaction_tag]


def set_transaction_timeout(instance_id, database_id):
"""Executes a transaction with a transaction timeout."""
# [START spanner_transaction_timeout]
# instance_id = "your-spanner-instance"
# database_id = "your-spanner-db-id"
spanner_client = spanner.Client()
instance = spanner_client.instance(instance_id)
database = instance.database(database_id)

def read_then_write(transaction):
# Read records.
results = transaction.execute_sql(
"SELECT SingerId, FirstName, LastName FROM Singers ORDER BY LastName, FirstName"
)
for result in results:
print("SingerId: {}, FirstName: {}, LastName: {}".format(*result))

# Insert a record.
row_ct = transaction.execute_update(
"INSERT INTO Singers (SingerId, FirstName, LastName) "
" VALUES (100, 'George', 'Washington')"
)
print("{} record(s) inserted.".format(row_ct))

# configure transaction timeout to 60 seconds
database.run_in_transaction(read_then_write, timeout_secs=60)
Comment thread
surbhigarg92 marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.


# [END spanner_transaction_timeout]


def set_request_tag(instance_id, database_id):
"""Executes a snapshot read with a request tag."""
# [START spanner_set_request_tag]
Expand Down Expand Up @@ -3272,6 +3302,7 @@ def update_instance_default_backup_schedule_type(instance_id):

print("Updated instance {} to have default backup schedules".format(instance_id))


# [END spanner_update_instance_default_backup_schedule_type]


Expand Down Expand Up @@ -3617,6 +3648,9 @@ def add_split_points(instance_id, database_id):
subparsers.add_parser("add_column", help=add_column.__doc__)
subparsers.add_parser("update_data", help=update_data.__doc__)
subparsers.add_parser("set_max_commit_delay", help=set_max_commit_delay.__doc__)
subparsers.add_parser(
"set_transaction_timeout", help=set_transaction_timeout.__doc__
)
subparsers.add_parser(
"query_data_with_new_column", help=query_data_with_new_column.__doc__
)
Expand Down Expand Up @@ -3783,6 +3817,8 @@ def add_split_points(instance_id, database_id):
update_data(args.instance_id, args.database_id)
elif args.command == "set_max_commit_delay":
set_max_commit_delay(args.instance_id, args.database_id)
elif args.command == "set_transaction_timeout":
set_transaction_timeout(args.instance_id, args.database_id)
elif args.command == "query_data_with_new_column":
query_data_with_new_column(args.instance_id, args.database_id)
elif args.command == "read_write_transaction":
Expand Down
7 changes: 7 additions & 0 deletions 7 samples/samples/snippets_test.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,13 @@ def test_set_transaction_tag(capsys, instance_id, sample_database):
assert "New venue inserted." in out


@pytest.mark.dependency(depends=["insert_datatypes_data"])
def test_set_transaction_timeout(capsys, instance_id, sample_database):
snippets.set_transaction_timeout(instance_id, sample_database.database_id)
out, _ = capsys.readouterr()
assert "1 record(s) inserted." in out


@pytest.mark.dependency(depends=["insert_data"])
def test_set_request_tag(capsys, instance_id, sample_database):
snippets.set_request_tag(instance_id, sample_database.database_id)
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.