Skip to content

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

Description

@dhermes

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:

>>>fromgcloudimportstorage>>>fromgcloud.storage.batchimportBatch>>>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'>>>>>>withBatch() asbatch:
... blob.patch()
...
<Blob: dsmlmsldfsacjnajdnkewee, foo>Traceback (mostrecentcalllast):
File"<stdin>", line2, in<module>File"gcloud/storage/batch.py", line165, in__exit__self.finish()
File"gcloud/storage/batch.py", line130, infinishraiseValueError("No deferred requests")
ValueError: Nodeferredrequests

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

>>>fromgcloudimportstorage>>>fromgcloud.storage.batchimportBatch>>>storage._PROJECT_ENV_VAR_NAME='GCLOUD_TESTS_PROJECT_ID'>>>storage.set_defaults()
>>>>>>withBatch() asbatch:
... 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_typeTraceback (mostrecentcalllast):
File"<stdin>", line1, in<module>File"gcloud/storage/_helpers.py", line163, in_getterreturnself.properties[fieldname]
File"gcloud/storage/_helpers.py", line64, inpropertiesreturnself._properties.copy()
AttributeError: 'str'objecthasnoattribute'copy'

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the Cloud Storage API.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions