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

[firestore-emulator] Queries don't work in "datastore-mode" #6827

Closed
artoale opened this issue Feb 29, 2024 · 1 comment
Closed

[firestore-emulator] Queries don't work in "datastore-mode" #6827

artoale opened this issue Feb 29, 2024 · 1 comment

Comments

@artoale
Copy link

artoale commented Feb 29, 2024

[REQUIRED] Environment info

firebase-tools: Using the gcloud cli version 465.0.0, firestore emulator: 1.19.1

Platform: macOS (intel)

[REQUIRED] Test case

import os

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

def main():
    def get_new_client():
        return datastore.Client(
            project=os.environ.get("GCLOUDC_PROJECT_ID", "test"),
            namespace=None,
            _http=None,
        )

    client = get_new_client()
    kind = "a_kind"
    query = client.query(kind=kind)
    res = query.add_filter(filter=PropertyFilter("username", "=", "a_username")).fetch()

    if len(list(res)) > 0:
        print("found!")
    else:
        print("not found!")

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. Set the DATASTORE_EMULATOR_HOST and DATASTORE_PROJECT_ID env vars accordingly
  4. Run the above python script

[REQUIRED] Expected behavior

Either "found!" or "not found!" is printed to console.

[REQUIRED] Actual behavior

An exception is raised:

Traceback (most recent call last):
  File "XXX/dev/experiments/firestore-emulator/./test_firestore_in_datastore.py", line 153, in <module>
    main()
  File "XXX/dev/experiments/firestore-emulator/./test_firestore_in_datastore.py", line 146, in main
    run_some_code()
  File "XXX/dev/experiments/firestore-emulator/./test_firestore_in_datastore.py", line 106, in run_some_code
    if len(list(res)) > 0:
           ^^^^^^^^^
  File "XXX/.pyenv/versions/firestore-emulator/lib/python3.11/site-packages/google/api_core/page_iterator.py", line 208, in _items_iter
    for page in self._page_iter(increment=False):
  File "XXX/.pyenv/versions/firestore-emulator/lib/python3.11/site-packages/google/api_core/page_iterator.py", line 244, in _page_iter
    page = self._next_page()
           ^^^^^^^^^^^^^^^^^
  File "XXX/.pyenv/versions/firestore-emulator/lib/python3.11/site-packages/google/cloud/datastore/query.py", line 845, in _next_page
    entity_pbs = self._process_query_results(response_pb)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "XXX/.pyenv/versions/firestore-emulator/lib/python3.11/site-packages/google/cloud/datastore/query.py", line 766, in _process_query_results
    raise ValueError("Unexpected value returned for `more_results`.")
ValueError: Unexpected value returned for `more_results`

Additional infos

For debugging purposes, I've inspected the returned response_pb and more_results is set to 0, equivalent to MORE_RESULTS_TYPE_UNSPECIFIED which, according to the spec, should never be provided.

@artoale artoale changed the title [firestore-emulator] Query don't work in "datastore-mode" [firestore-emulator] Queries don't work in "datastore-mode" Feb 29, 2024
@joehan
Copy link
Contributor

joehan commented Mar 5, 2024

Should be fixed by #6832, which will go out in the next release. Thanks for reporting this!

@joehan joehan closed this as completed Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants