Skip to content

feat(spanner): Add UpdateBackupSchedule cron and retention sample - #14986

Merged
amcolin merged 1 commit into
feat/spanner-copy-backupfrom
feat/spanner-update-backup-schedule
Nov 19, 2026
Merged

amcolin merged 1 commit into
feat/spanner-copy-backupfrom
feat/spanner-update-backup-schedule

Conversation

@iennae

@iennae iennae commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Description

Adds spanner_update_backup_schedule updating cron expression and retention duration on 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

Adjusting backup schedule frequency or retention window uses DatabaseAdminClient.update_backup_schedule with an update_mask. Add a standalone spanner_update_backup_schedule sample.
@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 update a Google Cloud Spanner backup schedule's cron frequency, retention duration, and encryption configuration. The review feedback recommends explicitly constructing the update mask using google.protobuf.field_mask_pb2.FieldMask instead of passing a raw dictionary, which improves type safety and aligns with Google Cloud Python client library best practices.

import sys

from google.api_core import exceptions
from google.cloud import spanner_admin_database_v1

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

Import field_mask_pb2 from google.protobuf to explicitly construct the FieldMask for the update request.

Suggested change
from google.cloud import spanner_admin_database_v1
from google.cloud import spanner_admin_database_v1
from google.protobuf import field_mask_pb2

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 the dictionary form: the update samples in this set all pass the mask as a dictionary, which the client accepts, so this one stays consistent with them.

Comment on lines +57 to +63
update_mask={
"paths": [
"spec.cron_spec.text",
"retention_duration",
"encryption_config",
]
},

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

Use field_mask_pb2.FieldMask to explicitly construct the update mask instead of passing a raw dictionary. This is more idiomatic, type-safe, and aligns with Google Cloud Python client library best practices.

Suggested change
update_mask={
"paths": [
"spec.cron_spec.text",
"retention_duration",
"encryption_config",
]
},
update_mask=field_mask_pb2.FieldMask(
paths=[
"spec.cron_spec.text",
"retention_duration",
"encryption_config",
]
),

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 the dictionary form: the update samples in this set all pass the mask as a dictionary, which the client accepts, so this one stays consistent with them.

@angelcaamal angelcaamal 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.

LGTM! Approved.

@amcolin
amcolin merged commit 544d52d into feat/spanner-copy-backup Nov 19, 2026
2 checks passed
@amcolin
amcolin deleted the feat/spanner-update-backup-schedule branch November 19, 2026 18:46
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.

3 participants