8000 Batch (and Transaction) dataset_id should match that of Key / Query objects when added · Issue #447 · googleapis/google-cloud-python · GitHub
[go: up one dir, main page]

Skip to content

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

@dhermes

Description

@dhermes

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}>

Metadata

Metadata

Assignees

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

    0