Skip to content

feat(spanner): Add ListBackupOperations progress inspection sample - #14981

Open
iennae wants to merge 2 commits into
feat/spanner-copy-backupfrom
feat/spanner-list-backup-operations
Open

iennae wants to merge 2 commits into
feat/spanner-copy-backupfrom
feat/spanner-list-backup-operations

Conversation

@iennae

@iennae iennae commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Description

Adds spanner_list_backup_operations listing CreateBackupMetadata and CopyBackupMetadata operations on an instance.

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

Monitoring active CreateBackup and CopyBackup operations filters DatabaseAdminClient.list_backup_operations by metadata type and resource. Add spanner_list_backup_operations.
@iennae
iennae requested review from a team as code owners November 18, 2026 22:19
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Nov 18, 2026
@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 the samples Issues that are directly related to samples. label 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, list_backup_operations.py, along with its corresponding tests, to list CreateBackup and CopyBackup long-running operations on a Google Cloud Spanner instance. The feedback suggests using fully qualified resource paths instead of simple IDs in the API filters to avoid unintended substring matches and ensure precise filtering.

Comment on lines +35 to +44
create_filter = (
"(metadata.@type:type.googleapis.com/"
"google.spanner.admin.database.v1.CreateBackupMetadata) "
f"AND (metadata.database:{database_id})"
)
copy_filter = (
"(metadata.@type:type.googleapis.com/"
"google.spanner.admin.database.v1.CopyBackupMetadata) "
f"AND (metadata.source_backup:{backup_id})"
)

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

Using a simple ID like database_id or backup_id in the filter with the : operator can lead to incorrect matches. Because : is a substring/contains operator, if the ID is a substring of the project ID, instance ID, or another database/backup name, the filter will match unintended resources. Constructing and using the fully qualified resource path ensures precise filtering.

    database_path = f"projects/{project_id}/instances/{instance_id}/databases/{database_id}"
    backup_path = f"projects/{project_id}/instances/{instance_id}/backups/{backup_id}"
    create_filter = (
        "(metadata.@type:type.googleapis.com/"
        "google.spanner.admin.database.v1.CreateBackupMetadata) "
        f"AND (metadata.database:{database_path})"
    )
    copy_filter = (
        "(metadata.@type:type.googleapis.com/"
        "google.spanner.admin.database.v1.CopyBackupMetadata) "
        f"AND (metadata.source_backup:{backup_path})"
    )

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 ID-based filter: it keeps the sample simple, and it is meant to be run with IDs that are unique within the instance.

Problem: review of this sample identified correctness and robustness
improvements in the sample and its tests.

Solution: apply the accepted review suggestions and extend the tests to
cover the updated behavior. Details are in the review thread replies.

Files updated:
  - spanner/backups/tests/list_backup_operations_test.py
@angelcaamal angelcaamal 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