Skip to content

feat(storage): add object contexts samples - #14668

Open
sahusneha2004 wants to merge 2 commits into
mainfrom
storage-object-contexts-samples-python
Open

sahusneha2004 wants to merge 2 commits into
mainfrom
storage-object-contexts-samples-python

Conversation

@sahusneha2004

Copy link
Copy Markdown

Add samples for setting, getting, listing (filter) and deleting GCS object contexts.

Region tags: storage_set_object_contexts, storage_get_object_contexts, storage_list_object_contexts, storage_delete_object_contexts.

  • storage_set_object_contexts.py: upsert key1/key3 and delete key2 (value=None) with a metageneration-match precondition.
  • storage_get_object_contexts.py: print an object's custom contexts.
  • storage_list_object_contexts.py: list objects using list_blobs(filter_=...) with context filters.
  • storage_delete_object_contexts.py: clear all contexts.

Requires google-cloud-storage >= 3.11.0 (already pinned at 3.14.1).

Tests: pytest snippets_test.py -k object_contexts -> 4 passed.

Internal bug: b/482946642

[Generated-by: AI]

@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Oct 22, 2026
@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Oct 22, 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 new sample snippets and corresponding integration tests for managing Google Cloud Storage object contexts, including setting, getting, listing, and deleting custom contexts. The review feedback highlights critical safety improvements across these snippets, specifically pointing out potential AttributeError exceptions if the requested blob does not exist (returning None) or if blob.contexts is uninitialized when attempting to set custom contexts.

Comment thread storage/samples/snippets/storage_set_object_contexts.py Outdated
Comment thread storage/samples/snippets/storage_get_object_contexts.py Outdated
Comment thread storage/samples/snippets/storage_delete_object_contexts.py Outdated
Add samples for setting, getting, listing (filter) and deleting GCS object contexts.

Region tags: storage_set_object_contexts, storage_get_object_contexts, storage_list_object_contexts, storage_delete_object_contexts.

Internal bug: b/482946642

[Generated-by: AI]
Switch the set/get/delete object-contexts samples from `bucket.get_blob()`
(which returns None for a missing object) to `bucket.blob()` + `blob.reload()`,
the idiom used by the other precondition-based samples in this directory, so a
missing object raises `google.api_core.exceptions.NotFound` instead of an
AttributeError. Drop the redundant `if blob.contexts` guard in the get sample:
`Blob.contexts` always returns an `ObjectContexts` instance.

Internal bug: b/482946642

[Generated-by: AI]
@sahusneha2004
sahusneha2004 force-pushed the storage-object-contexts-samples-python branch from 630cbcf to 153ef0d Compare October 27, 2026 20:00
@sahusneha2004
sahusneha2004 marked this pull request as ready for review October 27, 2026 20:06
@sahusneha2004
sahusneha2004 requested review from a team as code owners October 27, 2026 20:07
@snippet-bot

snippet-bot Bot commented Oct 27, 2026

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 4 region tags.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated api: storage Issues related to the Cloud Storage API. samples Issues that are directly related to samples. storage-sample-architect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants