Skip to content

feat(spanner): Add GetBackupSchedule inspection sample - #14984

Open
iennae wants to merge 1 commit into
feat/spanner-copy-backupfrom
feat/spanner-get-backup-schedule
Open

iennae wants to merge 1 commit into
feat/spanner-copy-backupfrom
feat/spanner-get-backup-schedule

Conversation

@iennae

@iennae iennae commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Description

Adds spanner_get_backup_schedule retrieving metadata for a Spanner backup schedule.

Note: Stacked on #14854 (feat/spanner-copy-backup) so this PR shows only this sample's diff. It will merge into main after #14854.

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

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.
@iennae
iennae requested review from a team as code owners November 18, 2026 22:20
@snippet-bot

snippet-bot Bot commented Nov 18, 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

@product-auto-label product-auto-label Bot added api: spanner Issues related to the Spanner API. samples Issues that are directly related to samples. labels Nov 18, 2026

@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 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}")

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

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.

Suggested change
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}")

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! 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.

@amcolin amcolin self-assigned this Nov 19, 2026
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