Repository navigation
Conversation
Inspecting cron and retention settings on a backup schedule calls DatabaseAdminClient.get_backup_schedule. Add a standalone spanner_get_backup_schedule sample with unit and live tests.
|
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 script and corresponding tests to retrieve and display metadata for a Cloud Spanner backup schedule. The review feedback recommends adding defensive checks when accessing the nested schedule.spec.cron_spec.text attribute to prevent potential AttributeError issues if other schedule specification types are introduced in the future.
| else: | ||
| retention_hours = int(schedule.retention_duration.total_seconds() // 3600) | ||
| print(f"Resource ID: {schedule_id}") | ||
| print(f"Cron Expression: {schedule.spec.cron_spec.text}") |
There was a problem hiding this comment.
To ensure the sample is robust and forward-compatible, avoid direct nested attribute access on schedule.spec.cron_spec. Since spec is a oneof field, if Spanner introduces other schedule specification types in the future, cron_spec will be None, leading to an AttributeError when accessing .text.
Using defensive checks or safe attribute retrieval ensures the sample handles such cases gracefully.
| print(f"Cron Expression: {schedule.spec.cron_spec.text}") | |
| cron_text = schedule.spec.cron_spec.text if schedule.spec and schedule.spec.cron_spec else "N/A" | |
| print(f"Cron Expression: {cron_text}") |
There was a problem hiding this comment.
Thanks! Keeping this as is: the field is populated in the responses this sample handles, and the extra branching would distract from what the sample shows.
Description
Adds
spanner_get_backup_scheduleretrieving metadata for a Spanner backup schedule.Checklist
Testing
Compliance & Style
spanner/, which the default repository owners cover.Post-Approval Actions