Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_PropertyMixin.patch() does not work as expected in a batch #736

Closed
dhermes opened this issue Mar 14, 2015 · 1 comment
Closed

_PropertyMixin.patch() does not work as expected in a batch #736

dhermes opened this issue Mar 14, 2015 · 1 comment
Assignees
Labels
api: storage Issues related to the Cloud Storage API.

Comments

@dhermes
Copy link
Contributor

dhermes commented Mar 14, 2015

One big takeaway is that connection should not be bound to Blob and Bucket (#728).


If the Bucket does not explicitly have the batch set as it's connection, the request happens outside the batch:

>>> from gcloud import storage
>>> from gcloud.storage.batch import Batch
>>> storage._PROJECT_ENV_VAR_NAME = 'GCLOUD_TESTS_PROJECT_ID'
>>> storage.set_defaults()
>>> bucket_name = 'dsmlmsldfsacjnajdnkewee'
>>> connection = storage.get_default_connection()
>>> bucket = storage.Bucket(name=bucket_name, connection=connection)
>>> blob = storage.Blob('foo', bucket=bucket)
>>> blob._reload_properties()
<Blob: dsmlmsldfsacjnajdnkewee, foo>
>>> blob.content_type = 'foo/bar'
>>>
>>> with Batch() as batch:
...     blob.patch()
...
<Blob: dsmlmsldfsacjnajdnkewee, foo>
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "gcloud/storage/batch.py", line 165, in __exit__
    self.finish()
  File "gcloud/storage/batch.py", line 130, in finish
    raise ValueError("No deferred requests")
ValueError: No deferred requests

On the other hand, if we do the setup correctly, it puts the blob in an undefined state (I referenced this some time ago):

>>> from gcloud import storage
>>> from gcloud.storage.batch import Batch
>>> storage._PROJECT_ENV_VAR_NAME = 'GCLOUD_TESTS_PROJECT_ID'
>>> storage.set_defaults()
>>>
>>> with Batch() as batch:
...     bucket_name = 'dsmlmsldfsacjnajdnkewee'
...     bucket = storage.Bucket(name=bucket_name, connection=batch)
...     blob = storage.Blob('foo', bucket=bucket)
...     blob.content_type = 'foo/bar'
...     blob.patch()
...
<Blob: dsmlmsldfsacjnajdnkewee, foo>
>>> blob._properties
''
>>> blob.content_type
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "gcloud/storage/_helpers.py", line 163, in _getter
    return self.properties[fieldname]
  File "gcloud/storage/_helpers.py", line 64, in properties
    return self._properties.copy()
AttributeError: 'str' object has no attribute 'copy'
@dhermes dhermes added the api: storage Issues related to the Cloud Storage API. label Mar 14, 2015
@dhermes dhermes added this to the Storage Stable milestone Mar 14, 2015
@dhermes
Copy link
Contributor Author

dhermes commented May 8, 2015

This was fixed in #812

@dhermes dhermes closed this as completed May 8, 2015
parthea pushed a commit that referenced this issue Oct 21, 2023
* feat: Update Compute Engine API to revision 20221011 (#736)

Source-Link: googleapis/googleapis@cb8c914

Source-Link: googleapis/googleapis-gen@1174767
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMTE3NDc2NzQ0NmM2NTAyNzFmMzk3ZWM2ZWY1NDEwMWJlNDRjZGNiNCJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API.
Projects
None yet
Development

No branches or pull requests

1 participant