Skip to content
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

Datastore batches distinguish between "" and None on delete_multi and throw #460

Open
rwhogg opened this issue Jul 20, 2023 · 0 comments
Open
Assignees
Labels
api: datastore Issues related to the googleapis/python-datastore API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@rwhogg
Copy link
Contributor

rwhogg commented Jul 20, 2023

Environment details

  • OS type and version: Linux
  • Python version: 3.8.15
  • pip version: 23.2
  • google-cloud-datastore version:
Name: google-cloud-datastore
Version: 2.16.1
Summary: Google Cloud Datastore API client library
Home-page: https://github.com/googleapis/python-datastore
Author: Google LLC
Author-email: googleapis-packages@google.com
License: Apache 2.0
Location: /home/rwhogg/.pyenv/versions/3.8.15/lib/python3.8/site-packages
Requires: google-api-core, google-cloud-core, proto-plus, protobuf
Required-by: google-cloud-ndb

Steps to reproduce

  1. Get some keys with database == ""
  2. Get a datastore client with database of None
  3. Call delete_multi on those keys

Code example

# batchbug.py
from google.cloud.datastore.client import Client

client = Client(project="myproject")

# Get some keys
query = client.query(kind="somekind")
query.keys_only()
for page in query.fetch().pages:
    keys = [entity.key for entity in page]

# Change the keys to have database == "".
# This isn't the normal way you would do this, it's just for reproducing the bug
keys = map(lambda k: k.__class__(
    *k.flat_path,
    project=k.project,
    database="",
    namespace=k.namespace
), keys)

# batch delete - throws error
client.delete_multi(keys)

Stack trace

Traceback (most recent call last):
  File "batchbug.py", line 18, in <module>
    client.delete_multi(keys)
  File "/home/rwhogg/.pyenv/versions/3.8.15/lib/python3.8/site-packages/google/cloud/datastore/client.py", line 721, in delete_multi
    current.delete(key)
  File "/home/rwhogg/.pyenv/versions/3.8.15/lib/python3.8/site-packages/google/cloud/datastore/batch.py", line 261, in delete
    raise ValueError("Key must be from same database as batch")
ValueError: Key must be from same database as batch
@product-auto-label product-auto-label bot added the api: datastore Issues related to the googleapis/python-datastore API. label Jul 20, 2023
@rwhogg rwhogg changed the title Datastore batches distinguish between "" and None on delete_multi Datastore batches distinguish between "" and None on delete_multi and throw Jul 20, 2023
@triplequark triplequark added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Oct 26, 2023
@daniel-sanche daniel-sanche added priority: p3 Desirable enhancement or fix. May not be included in next release. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. labels Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the googleapis/python-datastore API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants