Title: _PropertyMixin.patch() does not work as expected in a batch · Issue #736 · googleapis/google-cloud-python · GitHub
Open Graph Title: _PropertyMixin.patch() does not work as expected in a batch · Issue #736 · googleapis/google-cloud-python
X Title: _PropertyMixin.patch() does not work as expected in a batch · Issue #736 · googleapis/google-cloud-python
Description: 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 gc...
Open Graph Description: 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: >>...
X Description: 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...
Opengraph URL: https://github.com/googleapis/google-cloud-python/issues/736
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"_PropertyMixin.patch() does not work as expected in a batch","articleBody":"One big takeaway is that `connection` should not be bound to `Blob` and `Bucket` (#728).\n\n---\n\nIf the `Bucket` does not explicitly have the `batch` set as it's connection, the request happens outside the batch:\n\n``` python\n\u003e\u003e\u003e from gcloud import storage\n\u003e\u003e\u003e from gcloud.storage.batch import Batch\n\u003e\u003e\u003e storage._PROJECT_ENV_VAR_NAME = 'GCLOUD_TESTS_PROJECT_ID'\n\u003e\u003e\u003e storage.set_defaults()\n\u003e\u003e\u003e bucket_name = 'dsmlmsldfsacjnajdnkewee'\n\u003e\u003e\u003e connection = storage.get_default_connection()\n\u003e\u003e\u003e bucket = storage.Bucket(name=bucket_name, connection=connection)\n\u003e\u003e\u003e blob = storage.Blob('foo', bucket=bucket)\n\u003e\u003e\u003e blob._reload_properties()\n\u003cBlob: dsmlmsldfsacjnajdnkewee, foo\u003e\n\u003e\u003e\u003e blob.content_type = 'foo/bar'\n\u003e\u003e\u003e\n\u003e\u003e\u003e with Batch() as batch:\n... blob.patch()\n...\n\u003cBlob: dsmlmsldfsacjnajdnkewee, foo\u003e\nTraceback (most recent call last):\n File \"\u003cstdin\u003e\", line 2, in \u003cmodule\u003e\n File \"gcloud/storage/batch.py\", line 165, in __exit__\n self.finish()\n File \"gcloud/storage/batch.py\", line 130, in finish\n raise ValueError(\"No deferred requests\")\nValueError: No deferred requests\n```\n\nOn the other hand, if we do the setup correctly, it puts the `blob` in an undefined state (I [referenced](https://github.com/GoogleCloudPlatform/gcloud-python/pull/683#issuecomment-76275986) this some time ago):\n\n``` python\n\u003e\u003e\u003e from gcloud import storage\n\u003e\u003e\u003e from gcloud.storage.batch import Batch\n\u003e\u003e\u003e storage._PROJECT_ENV_VAR_NAME = 'GCLOUD_TESTS_PROJECT_ID'\n\u003e\u003e\u003e storage.set_defaults()\n\u003e\u003e\u003e\n\u003e\u003e\u003e with Batch() as batch:\n... bucket_name = 'dsmlmsldfsacjnajdnkewee'\n... bucket = storage.Bucket(name=bucket_name, connection=batch)\n... blob = storage.Blob('foo', bucket=bucket)\n... blob.content_type = 'foo/bar'\n... blob.patch()\n...\n\u003cBlob: dsmlmsldfsacjnajdnkewee, foo\u003e\n\u003e\u003e\u003e blob._properties\n''\n\u003e\u003e\u003e blob.content_type\nTraceback (most recent call last):\n File \"\u003cstdin\u003e\", line 1, in \u003cmodule\u003e\n File \"gcloud/storage/_helpers.py\", line 163, in _getter\n return self.properties[fieldname]\n File \"gcloud/storage/_helpers.py\", line 64, in properties\n return self._properties.copy()\nAttributeError: 'str' object has no attribute 'copy'\n```\n","author":{"url":"https://github.com/dhermes","@type":"Person","name":"dhermes"},"datePublished":"2015-03-14T21:23:56.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/736/google-cloud-python/issues/736"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b3f25270-64a1-6ed9-651a-dd55b0b543f9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D6DC:1171B:CE4F2C:114E136:6A4D7CCE |
| html-safe-nonce | 50e7a4def3b8d5ca5c454be64bcc529432c6fa1174eb27092bb349063f33ee32 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENkRDOjExNzFCOkNFNEYyQzoxMTRFMTM2OjZBNEQ3Q0NFIiwidmlzaXRvcl9pZCI6IjM1Mzg0Mzg1NTEyNDE1ODc5MTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 770867567cbbbbdf9336ba7f3b331d93d47a0ca8dc80c167a3961eab0809c27c |
| hovercard-subject-tag | issue:61697461 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/google-cloud-python/736/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c860f2317f75f85c0c8dd5a054b709f31451a46f8ecf5c41cbf722181fdb6f5b/googleapis/google-cloud-python/issues/736 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c860f2317f75f85c0c8dd5a054b709f31451a46f8ecf5c41cbf722181fdb6f5b/googleapis/google-cloud-python/issues/736 |
| og:image:alt | 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: >>... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dhermes |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7f8e15305e2ab58890ca84b830615e375f5df303cf471cafcba0c08272981be3 |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/google-cloud-python git https://github.com/googleapis/google-cloud-python.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 16316451 |
| octolytics-dimension-repository_nwo | googleapis/google-cloud-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 16316451 |
| octolytics-dimension-repository_network_root_nwo | googleapis/google-cloud-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8608b0750fc35e283e5ec5b094bff942d7a0e197 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width