Skip to content

feat(spanner): Add change stream DDL creation sample - #14855

Open
iennae wants to merge 5 commits into
mainfrom
feat/spanner-create-change-stream
Open

iennae wants to merge 5 commits into
mainfrom
feat/spanner-create-change-stream

Conversation

@iennae

@iennae iennae commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Description

Configuring a Cloud Spanner change stream with custom retention and allow_txn_exclusion = true from Python requires submitting CREATE CHANGE STREAM through DatabaseAdminClient.update_database_ddl.

Establishes spanner/change_streams and adds spanner_create_change_stream.

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended. Unit and live integration tests pass on Python 3.13.

Compliance & Style


Post-Approval Actions

  • Please merge this PR for me once it is approved

Creating a Spanner change stream with custom retention and transaction exclusion options previously had only SQL DDL snippets.
@iennae
iennae requested review from a team as code owners November 17, 2026 23:47
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Nov 17, 2026
@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Nov 17, 2026
@snippet-bot

snippet-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces Python samples for Cloud Spanner change streams, including a script to create a change stream via DDL and corresponding unit and integration tests. A review comment points out a redundant nested os.environ.get call in the test configuration file (conftest.py) that should be simplified.

Comment on lines +23 to +25
LIVE_DATABASE_ID = os.environ.get(
"SPANNER_DATABASE_ID", os.environ.get("SPANNER_DATABASE_ID", "")
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The environment variable lookup for SPANNER_DATABASE_ID is redundant because it calls os.environ.get nested within itself with the same key. This can be simplified to a single os.environ.get call.

LIVE_DATABASE_ID = os.environ.get("SPANNER_DATABASE_ID", "")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This comment refers to an earlier revision of this file; the code here has since been reworked in later commits, so this thread no longer applies to the current diff.

Avoids printing project identifiers in stdout or stderr and simplifies duplicate environment variable lookup in test configuration.
Prints only runtime resource and query results instead of hardcoded string literals.
Problem: the sample waits on a long-running operation with a client-side
timeout. When that wait expires the client raises TimeoutError, which is
not an API call error, so the sample ended with an unhandled traceback.

Solution: catch TimeoutError and print a clear message to stderr noting
that only the wait timed out and the operation may still be running (the
timeout does not cancel it). Add a unit test covering the new handler.
Problem: multi-line SQL and DDL statements were written as adjacent string
fragments. That style is easy to get wrong (a missing trailing space joins
two SQL tokens) and is harder to read than the statement itself, and the
samples in this set mixed it with triple-quoted SQL.

Solution: write each multi-line statement as a single triple-quoted string,
matching the layout already used by the other samples. Only whitespace
between SQL tokens changes; the statements are otherwise identical.

Files updated:
  - spanner/change_streams/src/spanner_change_streams/create_change_stream.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API. samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants