googleapis/python-datastore

Simple query times out 4 out of 5 times

MeLight opened this issue · 1 comments

from google.cloud import datastore
import datetime
from datetime import timedelta

client = datastore.Client()
result = client.query(kind='Shop').add_filter('plan_expiry', '>', datetime.datetime.today()-timedelta(days=3)).fetch(3)

for entity in result:
	print(entity.get('owner_email'))

Running this from the command line mostly produces a timeout. Running similar query on other entities in the Datastore produces less timeouts but still does very often.

Traceback (most recent call last):
  File "/home/user/stuff/myproject/venv/lib/python3.9/site-packages/google/api_core/grpc_helpers.py", line 72, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "/home/user/stuff/myproject/venv/lib/python3.9/site-packages/grpc/_channel.py", line 946, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/home/user/stuff/myproject/venv/lib/python3.9/site-packages/grpc/_channel.py", line 849, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.DEADLINE_EXCEEDED
        details = "Deadline Exceeded"
        debug_error_string = "UNKNOWN:Deadline Exceeded {created_time:"2023-01-16T22:24:12.003883865+02:00", grpc_status:4}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/user/stuff/myproject/venv/lib/python3.9/site-packages/google/api_core/retry.py", line 191, in retry_target
    return target()
  File "/home/user/stuff/myproject/venv/lib/python3.9/site-packages/google/api_core/timeout.py", line 120, in func_with_timeout
    return func(*args, **kwargs)
  File "/home/user/stuff/myproject/venv/lib/python3.9/site-packages/google/api_core/grpc_helpers.py", line 74, in error_remapped_callable
    raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.DeadlineExceeded: 504 Deadline Exceeded

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/user/stuff/myproject/stores.py", line 8, in <module>
    for entity in result:
  File "/home/user/stuff/myproject/venv/lib/python3.9/site-packages/google/api_core/page_iterator.py", line 208, in _items_iter
    for page in self._page_iter(increment=False):
  File "/home/user/stuff/myproject/venv/lib/python3.9/site-packages/google/api_core/page_iterator.py", line 244, in _page_iter
    page = self._next_page()
  File "/home/user/stuff/myproject/venv/lib/python3.9/site-packages/google/cloud/datastore/query.py", line 627, in _next_page
    response_pb = self.client._datastore_api.run_query(
  File "/home/user/stuff/myproject/venv/lib/python3.9/site-packages/google/cloud/datastore_v1/services/datastore/client.py", line 625, in run_query
    response = rpc(
  File "/home/user/stuff/myproject/venv/lib/python3.9/site-packages/google/api_core/gapic_v1/method.py", line 113, in __call__
    return wrapped_func(*args, **kwargs)
  File "/home/user/stuff/myproject/venv/lib/python3.9/site-packages/google/api_core/retry.py", line 349, in retry_wrapped_func
    return retry_target(
  File "/home/user/stuff/myproject/venv/lib/python3.9/site-packages/google/api_core/retry.py", line 207, in retry_target
    raise exceptions.RetryError(
google.api_core.exceptions.RetryError: Deadline of 60.0s exceeded while calling target function, last exception: 504 Deadline Exceeded

Please advise

Thanks for filing an issue. The Deadline Exceeded error is an error from the backend, and not an issue with the client library.
Can you please file a support ticket with Datastore? There's information about it here: https://cloud.google.com/datastore/docs/getting-support

Another thing you can do is to increase the timeout. The fetch function accepts a timeout parameter. By default it is 60 seconds, but you can adjust it from your side.

Hope this helps.