Repository navigation
Conversation
Creating a Spanner change stream with custom retention and transaction exclusion options previously had only SQL DDL snippets.
|
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
There was a problem hiding this comment.
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.
| LIVE_DATABASE_ID = os.environ.get( | ||
| "SPANNER_DATABASE_ID", os.environ.get("SPANNER_DATABASE_ID", "") | ||
| ) |
There was a problem hiding this comment.
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
Problem: reviewers of this sample set asked for stricter and clearer tests and for a single source of truth for dependencies. Mocks were created without a spec, so a renamed client argument would pass silently; the mocked wait timeout was raised from the API call instead of from the operation's result; live tests did not say which environment variables they need; and some tests carried leftover or repeated lines. Package dependencies were pinned in both pyproject.toml and requirements.txt. Solution: where applicable to the files below, patch client classes with autospec=True, raise the mocked TimeoutError from operation.result(), document the required environment variables above each live test and skip when one is missing, remove unused or duplicated test lines, and join string literals that the formatter had left split on one line. For package scaffolding, read dependencies from requirements.txt and update the README install command to match. Files updated: - spanner/change_streams/README.md - spanner/change_streams/pyproject.toml - spanner/change_streams/tests/create_change_stream_test.py
Description
Configuring a Cloud Spanner change stream with custom retention and
allow_txn_exclusion = truefrom Python requires submittingCREATE CHANGE STREAMthroughDatabaseAdminClient.update_database_ddl.Establishes
spanner/change_streamsand addsspanner_create_change_stream.Checklist
Testing
Compliance & Style
spanner/, which the default repository owners cover.Post-Approval Actions