Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Mar 31, 2026. It is now read-only.
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Bucket.delete_blobs doesn't call on_error in a batch context #659

Copy link
Copy link

Description

@jd185367
Issue body actions

Trying to delete a file that doesn't exist with Bucket.delete_blobs should call the function passed to the on_error arg (if provided) instead of raising an exception. That's the behavior I observe when calling this method normally, but trying to do this inside a batch deletion seems to ignore the passed function and throw the exception anyway (instead of calling the function like I'd expect).

This appears to be closely related to issue #31, but seemed a distinct enough use case to be worth mentioning.

Environment details

  • OS: Windows 10 Enterprise, Version 1909
  • Python version: 3.9.6
  • pip version: 21.2.4 (using the poetry package manager, v1.1.11)
  • google-cloud-storage version: 1.43.0

Steps to reproduce

  1. Create a bucket in a Google Cloud project and confirm you can connect to it from a Python script on your machine (GOOGLE_APPLICATION_CREDENTIALS set, etc).
  2. Run the example code below on the machine with at least 1 name in filenames that doesn't exist in the bucket.
  3. Confirm that print_blob_name is executed if the with gcs_client.batch(): line is removed, but an exception is thrown instead when it's present.

Code example

import google.cloud.storage

gcs_client = google.cloud.storage.Client()
bucket = gcs_client.lookup_bucket("bucket-name")
filenames = ["non_existent.png"]

def print_blob_name(blob: google.cloud.storage.blob.Blob):
    print(f"ERROR - tried to delete missing blob '{str(blob)}'")

with gcs_client.batch():
    bucket.delete_blobs(filenames, on_error=print_blob_name)

Stack trace

Traceback (most recent call last):
  File "C:\Users\jd185367\.pyenv\pyenv-win\versions\3.9.6\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\jd185367\.pyenv\pyenv-win\versions\3.9.6\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\jd185367\<redacted>\gcs_deletion_test.py", line 11, in <module>
    bucket.delete_blobs(filenames, on_error=print_blob_name)
  File "C:\Users\jd185367\AppData\Local\pypoetry\Cache\virtualenvs\<redacted>-I8hA3ptd-py3.9\lib\site-packages\google\cloud\storage\batch.py", line 299, in __exit__
    self.finish()
  File "C:\Users\jd185367\AppData\Local\pypoetry\Cache\virtualenvs\<redacted>-I8hA3ptd-py3.9\lib\site-packages\google\cloud\storage\batch.py", line 285, in finish
    self._finish_futures(responses)
  File "C:\Users\jd185367\AppData\Local\pypoetry\Cache\virtualenvs\<redacted>-I8hA3ptd-py3.9\lib\site-packages\google\cloud\storage\batch.py", line 261, in _finish_futures
    raise exceptions.from_http_response(exception_args)
google.api_core.exceptions.NotFound: 404 BATCH contentid://None: No such object: bucket-name/non_existent.png
Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the googleapis/python-storage API.Issues related to the googleapis/python-storage API.priority: p3Desirable enhancement or fix. May not be included in next release.Desirable enhancement or fix. May not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.