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 — Batch (and Transaction) dataset_id should match that of Key / Query objects when added · Issue #447 · googleapis/google-cloud-python

Batch (and Transaction) dataset_id should match that of Key / Query objects when added #447

New issue
Copy link
New issue
Copy link
Closed
#552
Closed
Batch (and Transaction) dataset_id should match that of Key / Query objects when added#447
#552
Copy link
Assignees
dhermes
Labels
🚨This issue needs some love.api: datastoreIssues related to the Datastore API.triage meI really want to be triaged.

Description

@dhermes
dhermes
opened on Dec 19, 2014
Issue body actions

Proposed fix:

Do not ask for dataset_id in the constructor and instead gather it from the keys and queries used in the transaction.

This may require implementing #495 and will require removing the self.begin() call from Transaction.__enter__. (Can't begin until a query or entity is encountered.)

Title was: "Transaction does not rollback correctly when multiple datasets involved"


Witness the following code:

>>> from gcloud import datastore
>>> cnxn = datastore.get_connection()
>>> dataset1 = cnxn.dataset('PROJ1')
>>> dataset2 = cnxn.dataset('PROJ2')
>>> e1 = dataset1.entity('foo')
>>> e2 = dataset2.entity('foo')
>>> e1['bar'] = e2['bar'] = 0
>>> e1.save()
<Entity[{'kind': u'foo', 'id': 5686683802533888L}] {'bar': 0}>
>>> e2.save()
<Entity[{'kind': u'foo', 'id': 5659313586569216L}] {'bar': 0}>
>>> with dataset1.transaction():
...     e1.delete()
...     e2.delete()
... 
>>> e1_still = dataset1.get_entity(e1.key())
>>> e1_still is None
True
>>> e2_still = dataset2.get_entity(e2.key())
>>> e2_still
<Entity[{'kind': u'foo', 'id': 5659313586569216L}] {u'bar': 0L}>

Activity

Next
  1. dhermes
    added
    api: datastoreIssues related to the Datastore API.
    on Dec 19, 2014
  2. dhermes commented on Dec 19, 2014

    @dhermes
    dhermes
    on Dec 19, 2014
    ContributorAuthor
    More actions

    UPDATE: This is because the transaction ignores the dataset associated with e2. To see this, we use the key

    <Key[{'kind': 'foo', 'id': 2}]>

    in two different datasets and delete the one from dataset2 in the transaction for dataset1. After doing this, we check if that key still exists in dataset1 (it should) and dataset2 (it should, but because the transaction failed since two different datasets were used).

    >>> from gcloud import datastore
    >>> cnxn = datastore.get_connection()
    >>> dataset1 = cnxn.dataset('PROJ1')
    >>> dataset2 = cnxn.dataset('PROJ2')
    >>> 
    >>> e1_1 = dataset1.entity('foo')
    >>> e1_1.key(e1_1.key().id(1))
    <Entity[{'kind': 'foo', 'id': 1}] {}>
    >>> e1_2 = dataset1.entity('foo')
    >>> e1_2.key(e1_2.key().id(2))
    <Entity[{'kind': 'foo', 'id': 2}] {}>
    >>> 
    >>> e2_2 = dataset2.entity('foo')
    >>> e2_2.key(e2_2.key().id(2))
    <Entity[{'kind': 'foo', 'id': 2}] {}>
    >>> 
    >>> e1_1['bar'] = e1_2['bar'] = e2_2['bar'] = 0
    >>> 
    >>> e1_1.save()
    <Entity[{'kind': 'foo', 'id': 1}] {'bar': 0}>
    >>> e1_2.save()
    <Entity[{'kind': 'foo', 'id': 2}] {'bar': 0}>
    >>> e2_2.save()
    <Entity[{'kind': 'foo', 'id': 2}] {'bar': 0}>
    >>> 
    >>> with dataset1.transaction():
    ...     e1_1.delete()
    ...     e2_2.delete()
    ... 
    >>> e1_1_still = dataset1.get_entity(e1_1.key())
    >>> e1_1_still is None
    True
    >>> e1_2_still = dataset1.get_entity(e1_2.key())
    >>> e1_2_still is None
    True
    >>> e2_2_still = dataset2.get_entity(e2_2.key())
    >>> e2_2_still
    <Entity[{'kind': u'foo', 'id': 2L}] {u'bar': 0L}>
  3. dhermes
    changed the title [-]Transaction does not rollback correctly when multiple datasets involved[/-] [+]Transaction dataset_id should come from Key / Query involved[/+] on Jan 7, 2015
  4. dhermes
    changed the title [-]Transaction dataset_id should come from Key / Query involved[/-] [+]Transaction dataset_id should come from Key / Query objects involved[/+] on Jan 7, 2015
  5. dhermes
    self-assigned this
    on Jan 7, 2015
  6. dhermes
    changed the title [-]Transaction dataset_id should come from Key / Query objects involved[/-] [+]Batch (and Transaction) dataset_id should come from Key / Query objects involved[/+] on Jan 9, 2015
  7. tseaver commented on Jan 15, 2015

    @tseaver
    tseaver
    on Jan 15, 2015
    Contributor
    More actions

    Note that calling beginTransaction requires the dataset ID (we can't do the RPC without it). We already made the dataset ID optional, falling back to the implicit one, but we cannot possibly rely on the keys, because we don't know them yet when we start the transaction.

    I think it would be reasonable to say that users who don't want to use the implicit dataset ID know that when they create the batch / transaction, and can easily pass it. We would then change the code in put / delete to reject any key not matching the one set in __init__.

  8. dhermes commented on Jan 15, 2015

    @dhermes
    dhermes
    on Jan 15, 2015
    ContributorAuthor
    More actions

    Yes I also came to this conclusion. Implicit saves us.

    This re-opens the question about reading the dataset ID from every single key via _get_dataset_id_from_keys.

  9. dhermes
    changed the title [-]Batch (and Transaction) dataset_id should come from Key / Query objects involved[/-] [+]Batch (and Transaction) dataset_id should match that of Key / Query objects when added[/+] on Jan 15, 2015
  10. dhermes commented on Jan 15, 2015

    @dhermes
    dhermes
    on Jan 15, 2015
    ContributorAuthor
    More actions

    @tseaver I renamed to reflect the change.

    Do you want to tackle this or should I?

  11. tseaver commented on Jan 15, 2015

    @tseaver
    tseaver
    on Jan 15, 2015
    Contributor
    More actions

    I'll take it.

  12. tseaver
    closed this as completedin #552on Jan 28, 2015
  13. jgeewax
    modified the milestone: This milestone has been deleted on Jan 30, 2015
  14. tseaver
    added a commit that references this issue on Jun 25, 2018

    Add bucket properties to support retention policy feature. (#447)

    6a1866e
  15. 17 remaining items

  16. parthea
    added a commit that references this issue on Sep 22, 2023

    docs: deprecate extra field to avoid confusion (#447)

    931ab78
  17. parthea
    added 4 commits that reference this issue on Oct 21, 2023

    fix(deps): require google-api-core>=1.32.0,>=2.8.0 (#447)

    8799d2a

    chore: use gapic generator python 1.4.1 (#447)

    7c7fc22

    chore(deps): update dependency pytest to v7.2.0 (#447)

    564e283

    feat: added Speech-to-Text V2 API (#447)

    05bf2ae
  18. parthea
    added a commit that references this issue on Aug 21, 2025

    chore(deps): update dependency ipython to v8.3.0 (#447)

    89f7476
  19. parthea
    added a commit that references this issue on Sep 16, 2025

    chore(deps): update dependency ipython to v8.3.0 (#447)

    6e6b0e0
  20. parthea
    added 5 commits that reference this issue on Nov 22, 2025

    chore: add py.typed file for PEP 561 compatibility (#447)

    33bf8cc

    chore(deps): update dependency google-api-core to v1.20.0 (#447)

    db81579

    feat: add json_fields extras argument for adding to jsonPayload (#447)

    ea9ce35

    fix: strip `order_by` option from query when using `count()` (#452)

    dddfe09

    feat: add json_fields extras argument for adding to jsonPayload (#447)

    061befd
  21. parthea
    added 3 commits that reference this issue on Mar 6, 2026

    ci: reduce number of workers for presubmit check (#447)

    92b6d99

    chore(deps): update dependency platformdirs to v2.6.2 (#447)

    6ba76d2

    feat: media operation retries can be configured using the same interf…

    168a942
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @dhermes
    dhermes

Labels

🚨This issue needs some love.api: datastoreIssues related to the Datastore API.triage meI really want to be triaged.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    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.