Skip to content

Fix #351: batch updates via context manager #352

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

Merged
merged 4 commits into from
Nov 7, 2014
Merged

Fix #351: batch updates via context manager #352

merged 4 commits into from
Nov 7, 2014

Conversation

tseaver
Copy link
Contributor

@tseaver tseaver commented Nov 7, 2014

See #351.

Add 'batch' property to '_PropertyMixin'.

  • Defers / aggregates repeated calls to '_patch_properties' within the scope of a 'with foo.batch:' block.
  • Issues a single '_patch_properties' call with the aggregated dict, IFF the block exits without an exception.
  • If an exception is raised from the with block, all changes are discarded.

E.g:

with key.batch:
    key.content_type = 'image/jpeg'
    key.content_disposition = 'attachment; filename="photo.jpg"'

results in a single PATCH request, with payload:

{'contentType': 'image/jpeg', 'contentDisposition': 'attachment; filename="photo.jpg"'}

They are opinionated, and not usefully so for our use cases:

- Data mapping objects have methods based on schema, not an a priori
  thumb rule.

- Context managers may have *no* public methods.
- Defers / aggregates repeated calls to '_patch_properties' within the scope
  of a 'with foo.batch:' block.

- Issues a single '_patch_properties' call with the aggregated dict, IFF
  the block exits without an exception.
@tseaver tseaver added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. api: storage Issues related to the Cloud Storage API. labels Nov 7, 2014
E.g., to batch multiple updates::

>>> with instance.batch:
... instance._patch_properties({'foo': 'Foo'})

This comment was marked as spam.

@dhermes
Copy link
Contributor

dhermes commented Nov 7, 2014

This is great!

LGTM except for the Travis lint failure.

Ping me after fixing so I can do a final pass.

@tseaver
Copy link
Contributor Author

tseaver commented Nov 7, 2014

The Travis failure is actually a bug in the "optimize lint" code: because not all files are considered, the 'abstract-class-not-used' warning kicks in. I can "fix" the failure by checking in a spurious change to bucket.py or key.py.

@dhermes
Copy link
Contributor

dhermes commented Nov 7, 2014

Aha! That seems like the easiest get-out-of-jail free card for this PR.

Any ideas for how to fix this going forward? (I know its my hack, but no good ideas come to mind quickly.)

Seems unlikely enough that maybe we just don't waste engineering effort on trying to fix this corner case?

@tseaver
Copy link
Contributor Author

tseaver commented Nov 7, 2014

I'd be tempted to just disable the pylint abstract-class-not-used and abstract-class-little-used checks, myself.

@dhermes
Copy link
Contributor

dhermes commented Nov 7, 2014

They are helpful in finding dead code. IMO, the more "out-of-the-box" our usage of pylint the better.

@dhermes
Copy link
Contributor

dhermes commented Nov 7, 2014

@tseaver Green Travis, feel free to merge.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 245b0e9 on tseaver:351-batch_updates_via_context_manager into * on GoogleCloudPlatform:master*.

@tseaver
Copy link
Contributor Author

tseaver commented Nov 7, 2014

I find it over-opinionated, myself.

tseaver added a commit that referenced this pull request Nov 7, 2014
…nager

Fix #351: batch updates via context manager
@tseaver tseaver merged commit 8536991 into googleapis:master Nov 7, 2014
@tseaver tseaver deleted the 351-batch_updates_via_context_manager branch November 7, 2014 01:27
parthea pushed a commit that referenced this pull request Jun 4, 2023
Source-Link: googleapis/synthtool@1b9ad76
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:9db98b055a7f8bd82351238ccaacfd3cda58cdf73012ab58b8da146368330021
parthea pushed a commit that referenced this pull request Jun 4, 2023
* docs: Fix formatting of request arg in docstring

chore: Update gapic-generator-python to v1.9.1
PiperOrigin-RevId: 518604533

Source-Link: googleapis/googleapis@8a085ae

Source-Link: googleapis/googleapis-gen@b2ab4b0
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYjJhYjRiMGEwYWUyOTA3ZTgxMmMyMDkxOThhNzRlMDg5OGFmY2IwNCJ9

* 🦉 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>
parthea pushed a commit that referenced this pull request Jun 4, 2023
…352)

Source-Link: googleapis/synthtool@95d9289
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:c8878270182edaab99f2927969d4f700c3af265accd472c3425deedff2b7fd93

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea added a commit that referenced this pull request Jul 6, 2023
parthea pushed a commit that referenced this pull request Sep 22, 2023
* docs: mention that some fields are deprecated

PiperOrigin-RevId: 519755058

Source-Link: googleapis/googleapis@26b4d27

Source-Link: googleapis/googleapis-gen@7ad7fcf
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiN2FkN2ZjZjllNWQyYThiMjQzOTM1ZWMyMDk1NGZiMjkwMTg1ODkxNSJ9

* 🦉 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>
parthea added a commit that referenced this pull request Sep 22, 2023
Source-Link: googleapis/synthtool@5f2a608
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:8555f0e37e6261408f792bfd6635102d2da5ad73f8f09bcb24f25e6afb5fac97

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <[email protected]>
parthea pushed a commit that referenced this pull request Sep 22, 2023
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
parthea added a commit that referenced this pull request Sep 22, 2023
* chore(python): add support for python 3.11

Source-Link: googleapis/synthtool@7197a00
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:c43f1d918bcf817d337aa29ff833439494a158a0831508fda4ec75dc4c0d0320

* trigger CI

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Anthonios Partheniou <[email protected]>
parthea pushed a commit that referenced this pull request Sep 22, 2023
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
parthea added a commit that referenced this pull request Oct 21, 2023
parthea pushed a commit that referenced this pull request Oct 21, 2023
parthea pushed a commit that referenced this pull request Oct 21, 2023
parthea added a commit that referenced this pull request Oct 21, 2023
* chore: use gapic-generator-python 0.65.2

PiperOrigin-RevId: 444333013

Source-Link: googleapis/googleapis@f91b6cf

Source-Link: googleapis/googleapis-gen@16eb360
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMTZlYjM2MDk1YzI5NGU3MTJjNzRhMWJmMjM1NTA4MTdiNDIxNzRlNSJ9

* 🦉 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>
Co-authored-by: Anthonios Partheniou <[email protected]>
parthea added a commit that referenced this pull request Oct 21, 2023
parthea pushed a commit that referenced this pull request Oct 21, 2023
Co-authored-by: release-please[bot] <55107282+release-please[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. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants