Repository navigation
Conversation
Exporting or auditing active Spanner table, index, and graph definitions calls DatabaseAdminClient.get_database_ddl. Add a standalone spanner_get_database_ddl sample and test suite.
|
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 a new module get_database_ddl.py and its associated tests to retrieve and print schema DDL statements for a Google Cloud Spanner database. Feedback on the changes points out a potential IndexError when parsing empty or whitespace-only DDL statements, suggesting a safer check before accessing the first line of the split statement.
| for statement in statements: | ||
| first_line = statement.strip().splitlines()[0] | ||
| print(f"DDL Statement: {first_line}") |
There was a problem hiding this comment.
If a DDL statement is empty or contains only whitespace, statement.strip().splitlines() will return an empty list, causing an IndexError when accessing the first element [0]. It is safer to check if the list is non-empty before accessing its elements.
| for statement in statements: | |
| first_line = statement.strip().splitlines()[0] | |
| print(f"DDL Statement: {first_line}") | |
| for statement in statements: | |
| lines = statement.strip().splitlines() | |
| first_line = lines[0] if lines else "" | |
| print(f"DDL Statement: {first_line}") |
There was a problem hiding this comment.
Thanks! Keeping this as is: the statements returned for a database's schema are not empty, and the extra branching would distract from what the sample shows.
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/database_admin/tests/get_database_ddl_test.py
Description
Adds
spanner_get_database_ddlretrieving schema DDL statements viaDatabaseAdminClient.get_database_ddl.Checklist
Testing
Compliance & Style
spanner/, which the default repository owners cover.Post-Approval Actions