firebase / firebase/firebase-tools

[firestore-emulator: datastore-mode] Kind query return empty list

Open
#6,903 4 comments 4 reactions 1 assignee Claimed by @harshyyy21 View on GitHub
emulators: firestore type: bug
Dominant language
TypeScript
Stars
4.5k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
84

Description

### General description

dastore-mode does not support [Kind Queries](https://cloud.google.com/datastore/docs/samples/datastore-kind-run-query)

This is absolutely essential to support using the emulator in a testing environment, since you need to be able to list all the kinds in the db to be able to (potentially selectively) delete all of them.

### [REQUIRED] Environment info

**firebase-tools:** Using the gcloud cli version 468.0.0, firestore emulator: 1.19.3

**Platform:** macOS (intel), python client library

### [REQUIRED] Test case

```python
import os

from google.cloud import datastore
from google.cloud.datastore.query import PropertyFilter

def main():
PORT = 10901
os.environ["DATASTORE_EMULATOR_HOST"] = "127.0.0.1:%s" % PORT
os.environ["DATASTORE_PROJECT_ID"] = "test"

def get_new_client():
return datastore.Client(
project="test",
namespace=None,
_http=None,
)

client = get_new_client()

kind = "a_kind"
key = client.key(kind)
entity = datastore.Entity(key=key)
entity.update({"foo": "bar"})

client.put(entity)

all_kinds = list(client.query(kind="__kind__").fetch())
print(all_kinds)
assert kind in [x.key.name for x in all_kinds]

if __name__ == "__main__":
main()
```

### [REQUIRED] Steps to reproduce
1. Start the emulator with `gcloud emulators firestore start --host-port=127.0.0.1:10901 --database-mode=datastore-mode`
2. Install the python deps: `pip install google-cloud-datastore==2.19.0`
3. Run the above python script

### [REQUIRED] Expected behavior

Completes, printing the following output:
```
[]
```

### [REQUIRED] Actual behavior
Output is
```
[]
```
and the assertion fails.

### Additional information

Note: the same test works as expected with both a real datastore instance or the old legacy datastore emulator

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.