GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Push batch / transaction onto a thread-local stack inside 'with'. by tseaver · Pull Request #518 · googleapis/google-cloud-python

Conversation

@tseaver

@tseaver tseaver commented Jan 8, 2015

Copy link
Copy Markdown
Contributor

Prep. for #514.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tseaver
Push batch / transaction onto a thread-local stack inside 'with'.
e5e4518
Prep. for #514.
@dhermes dhermes mentioned this pull request Jan 8, 2015
Decouple Transaction from Connection #514
Closed
8 tasks done
@coveralls

coveralls commented Jan 8, 2015

Copy link
Copy Markdown

Coverage Status

Coverage remained the same when pulling e5e4518 on tseaver:push_batch_xact_on_stack_in_context_mgr into 77cfe10 on GoogleCloudPlatform:master.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

dhermes
dhermes reviewed Jan 8, 2015
View reviewed changes
Comment thread gcloud/datastore/batch.py

This comment was marked as spam.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver
Give '_Batches' methods more natural names.
8190f4c
Add explicit test of using the stack.
@coveralls

coveralls commented Jan 8, 2015

Copy link
Copy Markdown

Coverage Status

Coverage remained the same when pulling 8190f4c on tseaver:push_batch_xact_on_stack_in_context_mgr into 77cfe10 on GoogleCloudPlatform:master.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Jan 8, 2015

Copy link
Copy Markdown
Contributor Author

Nesting batches "works": it just "suspends" the outer batch until the inner one exits. It does mean that the "inner" changes will be sent to the back-end before the "outer" ones, but folks using Batch aren't supposed to care about that, right?

The problem I was trying to solve was to make discovery of any current batch / transaction straightforward, even if the application does weird stuff like nesting (maybe accidentally).

If nesting is not a desirable feature, then we can close this PR and do something like your suggestion instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Jan 8, 2015

Copy link
Copy Markdown
Contributor Author

Motivating example:

from gcloud.datastore.batch import _BATCHES, Batch

def put(*entities):
    current = _BATCHES.top
    in_batch = current is not None
    if not in_batch:
        current = Batch()
    for entity in entities:
        current.put(entity)
    if not in_batch:
        current.commit()

def delete(*keys):
    current = _BATCHES.top
    in_batch = current is not None
    if not in_batch:
        current = Batch()
    for key in keys:
        current.delete(key)
    if not in_batch:
        current.commit()

which will all Just Work(TM) even in the face of nesting.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Jan 8, 2015

Copy link
Copy Markdown
Contributor

I keep confusing myself. The key focus here is that with must be called and when __exit__ occurs the stack is happy. Hence there is no such thing as interleaving.

That said, I still think the maintenance cost of a stack is not worth the minimal gain in functionality (which many users may never see). Users motivated enough to want nested / conditional transactions can accomplish the same thing with the API provided byBatch. The complexity becomes their burden, not ours.

I'm torn between "it already works as intended" and "let's not add code that we don't need to".

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Jan 8, 2015

Copy link
Copy Markdown
Contributor Author

That's actually why I made _BATCHES private (only capitalized as a sop to pylint :): Nobody but us chickens should touch it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Jan 8, 2015

Copy link
Copy Markdown
Contributor

It's not us touching it that worries me, it's bugs from exotic usage in the wild that we don't / won't have bandwidth or desire to deal with.

For example, what if someone calls a method that uses a context manager under the hood, and they expect

with Transaction() as txn:
    funky_save()

to save in txn when instead it spawns a new transaction and doesn't save there.

As I said, I don't think the burden of a larger surface area justifies the small set of use cases that this enables syntactically.

I'm much more comfortable

  • Clearly documenting nesting is not allowed
  • Throwing an error if nesting is attempted
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Jan 8, 2015

Copy link
Copy Markdown
Contributor Author

I don't see how your example is problematic: if funky_save manages its own transaction, separate from the surrounding one, their changes will still be saved, but just not "atomically" with txn's changes: that would be what they want, presumably (or they wouldn't code funky_save that way). We aren't doing damage by supporting nesting.

@silvolu Do the other mappings support nesting?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Jan 8, 2015

Copy link
Copy Markdown
Contributor

I'm not saying the functionality is damaging, I'm saying the maintenance burden on us is not worth it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@tseaver

tseaver commented Jan 8, 2015

Copy link
Copy Markdown
Contributor Author

Hmm, the maintenance / explainability of the consistent / nested one seems easier to me than maintaining / explaining the "Highlander" case.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Jan 8, 2015

Copy link
Copy Markdown
Contributor

I suppose you're right. I'm probably just being paranoid. Let's hope it doesn't bite us.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dhermes

dhermes commented Jan 8, 2015

Copy link
Copy Markdown
Contributor

LGTM

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tseaver added a commit that referenced this pull request Jan 8, 2015
@tseaver
Merge pull request #518 from tseaver/push_batch_xact_on_stack_in_cont…
7c01fcc
…ext_mgr

Push batch / transaction onto a thread-local stack inside 'with'.
@tseaver
tseaver merged commit 7c01fcc into googleapis:master Jan 8, 2015
@dhermes dhermes mentioned this pull request Jan 8, 2015
Removing dataset_id from allocate_ids and get_entities #510
Merged
@tseaver
tseaver deleted the push_batch_xact_on_stack_in_context_mgr branch January 8, 2015 22:14
@dhermes dhermes mentioned this pull request Jan 8, 2015
Factor out mutation-setting logic from 'Connection'. #524
Merged
dhermes added a commit to dhermes/google-cloud-python that referenced this pull request Jan 9, 2015
@dhermes
Adding api.delete() and removing Key.delete().
c5a634f
Also:
- Changing api.get() back to accept only `keys` and
  returns only a list (a lot of headache for not much
  gain).
- Factored out behavior to extract shared dataset_id from
  a set of keys into _get_dataset_id_from_keys().
- Updated docstrings and other tests that rely on changed /
  removed methods.

See googleapis#518 for some context.
@dhermes dhermes mentioned this pull request Jan 9, 2015
Adding api.delete() and removing Key.delete(). #527
Merged
dhermes added a commit to dhermes/google-cloud-python that referenced this pull request Jan 12, 2015
@dhermes
Adding api.delete() and removing Key.delete().
697d50c
Also:
- Changing api.get() back to accept only `keys` and
  returns only a list (a lot of headache for not much
  gain).
- Factored out behavior to extract shared dataset_id from
  a set of keys into _get_dataset_id_from_keys().
- Updated docstrings and other tests that rely on changed /
  removed methods.

See googleapis#518 for some context.
dhermes added a commit to dhermes/google-cloud-python that referenced this pull request Jan 12, 2015
@dhermes
Adding api.delete() and removing Key.delete().
ac3f9b1
Also:
- Changing api.get() back to accept only `keys` and
  returns only a list (a lot of headache for not much
  gain).
- Factored out behavior to extract shared dataset_id from
  a set of keys into _get_dataset_id_from_keys().
- Updated docstrings and other tests that rely on changed /
  removed methods.

See googleapis#518 for some context.
@dhermes dhermes added the api: datastore Issues related to the Datastore API. label Dec 31, 2015
parthea added a commit that referenced this pull request Aug 15, 2023
@parthea @gcf-owl-bot
chore: Prepare for mono repository migration (#518)
1c29fd1
* chore: Prepare for mono repository migration

* 🦉 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>
vchudnov-g pushed a commit that referenced this pull request Sep 20, 2023
@gcf-owl-bot
chore(python): auto approve template changes (#518)
1f6af30
Source-Link: googleapis/synthtool@453a5d9
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:81ed5ecdfc7cac5b699ba4537376f3563f6f04122c4ec9e735d3b3dc1d43dd32
parthea pushed a commit that referenced this pull request Sep 22, 2023
@gcf-owl-bot
build(deps): bump cryptography from 38.0.3 to 39.0.1 in /synthtool/gc…
fc9f8f4
…p/templates/python_library/.kokoro (#518)

Source-Link: https://togithub.com/googleapis/synthtool/commit/bb171351c3946d3c3c32e60f5f18cee8c464ec51
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:f62c53736eccb0c4934a3ea9316e0d57696bb49c1a7c86c726e9bb8a2f87dadf
parthea pushed a commit that referenced this pull request Sep 22, 2023
@gcf-owl-bot
build: [autoapprove] bump cryptography from 41.0.2 to 41.0.3 (#518)
2102271
Source-Link: https://togithub.com/googleapis/synthtool/commit/352b9d4c068ce7c05908172af128b294073bf53c
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:3e3800bb100af5d7f9e810d48212b37812c1856d20ffeafb99ebe66461b61fc7
parthea pushed a commit that referenced this pull request Oct 21, 2023
@gcf-owl-bot
chore(python): update dependencies in .kokoro/requirements.txt [autoa…
598b2d8
…pprove] (#518)

Source-Link: https://togithub.com/googleapis/synthtool/commit/e3a1277ac35fc88c09db1930533e24292b132ced
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:452901c74a22f9b9a3bd02bce780b8e8805c97270d424684bff809ce5be8c2a2
parthea added a commit that referenced this pull request Oct 21, 2023
@gcf-owl-bot @parthea
chore(python): add support for python 3.11 (#518)
e0cad55
Source-Link: googleapis/synthtool@7197a00
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:c43f1d918bcf817d337aa29ff833439494a158a0831508fda4ec75dc4c0d0320

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 Aug 21, 2025
@renovate-bot @parthea
chore(deps): update dependency google-auth to v2.12.0 (#518)
777206c
Co-authored-by: Anthonios Partheniou <[email protected]>
parthea added a commit that referenced this pull request Sep 16, 2025
@renovate-bot @parthea
chore(deps): update dependency google-auth to v2.12.0 (#518)
e377e59
Co-authored-by: Anthonios Partheniou <[email protected]>
parthea pushed a commit that referenced this pull request Sep 18, 2025
@gcf-owl-bot
chore(python): add nox session to sort python imports (#518)
b65d225
Source-Link: googleapis/synthtool@1b71c10
Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:00c9d764fd1cd56265f12a5ef4b99a0c9e87cf261018099141e2ca5158890416

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this pull request Nov 24, 2025
@release-please
chore: release 0.26.6 (#518)
78f4611
* updated CHANGELOG.md [ci skip]

* updated setup.py

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this pull request Nov 24, 2025
@gcf-owl-bot
fix: Retry and timeout values do not propagate in requests during pag…
d7cb375
…ination (#518)

* chore: Update gapic-generator-python to v1.18.4

PiperOrigin-RevId: 657207628

Source-Link: googleapis/googleapis@33fe71e

Source-Link: googleapis/googleapis-gen@e02739d
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZTAyNzM5ZDEyMmVkMTViZDVlZjU3NzFjNTdmMTJhODNkNDdhMWRkYSJ9

* 🦉 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 Nov 24, 2025
@kolea2
test: temporarily pin pytest-asyncio to < 0.17.0 (#522)
49e9fa7
Fixes #518

We'll need to identify the longer term fix here, but this will unblock current CI failures
parthea pushed a commit that referenced this pull request Nov 24, 2025
@Mariatta
test: Make the tests pass in pytest-asyncio>=0.17 (#525)
753c69a
Fixes #518

Unpin pytest-asyncio version.
Adjust the event_loop fixture to make it compatible with pytest-asyncio>=0.17
Use the @pytest_asyncio.fixture decorator for apropriately.
parthea pushed a commit that referenced this pull request Nov 26, 2025
@release-please
chore: release 1.16.0 (#518)
6d8a257
* updated CHANGELOG.md [ci skip]

* updated setup.cfg [ci skip]

* updated setup.py

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
parthea pushed a commit that referenced this pull request Mar 2, 2026
@tseaver
feat: add support for Python 3.10 (#518)
9d6792f
parthea pushed a commit that referenced this pull request Mar 2, 2026
@release-please
chore: release 2.9.0 (#522)
5ebed69
🤖 I have created a release \*beep\* \*boop\*
---
## [2.9.0](https://www.github.com/googleapis/python-pubsub/compare/v2.8.0...v2.9.0) (2021-11-10)


### Features

* add context manager support in client ([#516](https://www.github.com/googleapis/python-pubsub/issues/516)) ([51eae67](https://www.github.com/googleapis/python-pubsub/commit/51eae67c47e2ce7d2f7620209e98df4a129801b5))
* add support for Python 3.10 ([#518](https://www.github.com/googleapis/python-pubsub/issues/518)) ([bb25d75](https://www.github.com/googleapis/python-pubsub/commit/bb25d755d70ba19e69d8a281be65f13eb994967d))


### Bug Fixes

* add 'dict' annotation type to 'request' ([b72522a](https://www.github.com/googleapis/python-pubsub/commit/b72522a4617c4b2773fb6a5a631038791aa08300))
* **deps:** drop packaging dependency ([290b9c5](https://www.github.com/googleapis/python-pubsub/commit/290b9c5615eaa03674b773a27b756483abd76195))
* **deps:** require google-api-core >= 1.28.0 ([290b9c5](https://www.github.com/googleapis/python-pubsub/commit/290b9c5615eaa03674b773a27b756483abd76195))
* improper types in pagers generation ([2ad639d](https://www.github.com/googleapis/python-pubsub/commit/2ad639d6370c7a085498595d7bd0d7eaadfff3c1))


### Documentation

* add type annotations to codebase ([#509](https://www.github.com/googleapis/python-pubsub/issues/509)) ([093cabf](https://www.github.com/googleapis/python-pubsub/commit/093cabff9f0464b1dfaa8f373b6fffbc439518de))
* list oneofs in docstring ([290b9c5](https://www.github.com/googleapis/python-pubsub/commit/290b9c5615eaa03674b773a27b756483abd76195))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
parthea pushed a commit that referenced this pull request Mar 6, 2026
@arithmetic1728
test: update system test for mtls (#518)
bcdc44a
parthea pushed a commit that referenced this pull request Mar 9, 2026
@renovate-bot
chore(deps): update dependency pyjwt to v2.10.0 (#518)
9da0fde
parthea pushed a commit that referenced this pull request Mar 9, 2026
@tseaver
tests: use 120 sec timeout for 'blob.delete' during teardown (#518)
f5fc1e1
Closes #517
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

api: datastore Issues related to the Datastore API.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@tseaver @coveralls @dhermes
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.