You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Firestore: Using offset greater than 1000 on a query doesn't work #6924
ValueError: Unexpected server response. All responses other than the first must contain a document. The response at index 1 was
read_time {
seconds: 1544736718
nanos: 109409000
}
skipped_results: 1
.
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Source/....../scripts/.......py", line 21, in <module>
for document in documents:
File "/Source/......../venv/lib/python3.6/site-packages/google/cloud/firestore_v1beta1/query.py", line 599, in get
raise ValueError(msg)
ValueError: Unexpected server response. All responses other than the first must contain a document. The response at index 1 was
read_time {
seconds: 1544741917
nanos: 761441000
}
skipped_results: 1
.
I am certain there are more than 1000 documents as making the same query with an offset of 1000, returns more documents.
There is no indication in the StructuredQuery API docs of any upper bound on limit, and the google-cloud-firestore code doesn't do anything particular with the value beyond copying it into that message.
@shollyman Can you shed light on why the server would be returning a RunQueryResponse here with no document set? If it is expected, what is the expected behavior within the client library?
File "/usr/local/lib/python3.7/site-packages/google/cloud/firestore_v1beta1/query.py", line 758, in get
raise ValueError(msg)
ValueError: Unexpected server response. All responses other than the first must contain a document. The response at index 1 was
read_time {
seconds: 1547577043
nanos: 738488000
}
skipped_results: 200
has following response after getting ~2k documents out
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-9-e21161698f76> in <module>
7 while True:
8 t_query = t_collection.offset(cursor).limit(page_size)
----> 9 docs = [x.to_dict() for x in list(t_query.get())]
10 if(len(docs)) == 0 or cursor >= limit:
11 break
~/.virtualenvs/broadleaf/lib/python3.7/site-packages/google/cloud/firestore_v1beta1/query.py in get(self, transaction)
756 if index != 0:
757 msg = _EMPTY_DOC_TEMPLATE.format(index, response_pb)
--> 758 raise ValueError(msg)
759 empty_stream = skipped_results == 0
760 else:
ValueError: Unexpected server response. All responses other than the first must contain a document. The response at index 1 was
read_time {
seconds: 1548254968
nanos: 205102000
}
skipped_results: 1000
.
Looking at Query.get, which loops over the stream of RunQueryResponse messages, ISTM that we could just not raise the error for the empty document. In fact, the whole thing could be simplified to the following, given that we don't return the skipped_results anywhere:
I don't think raising exceptions about potential error cases from the back-end (non-empty response after empty first response, empty response after non-empty response) is useful here, given that we know the back end can return the empty response beyond the first one.
Activity
tseaver commentedon Dec 13, 2018
Can you please show the whole traceback? Also, are you sure there are at least 1000 documents in the collection?
KiwiPolarBear commentedon Dec 13, 2018
Sure.
I am certain there are more than 1000 documents as making the same query with an offset of 1000, returns more documents.
tseaver commentedon Dec 13, 2018
There is no indication in the
StructuredQueryAPI docs of any upper bound onlimit, and thegoogle-cloud-firestorecode doesn't do anything particular with the value beyond copying it into that message.@shollyman Can you shed light on why the server would be returning a
RunQueryResponsehere with nodocumentset? If it is expected, what is the expected behavior within the client library?hishnash commentedon Jan 14, 2019
on: 0.31.0
my stack trace is when I do
.offset(1001)timkock commentedon Jan 23, 2019
same issue, abandoning firestore for the moment as we can't get data out
has following response after getting ~2k documents out
tseaver commentedon Jan 23, 2019
Hmm, looking at the API docs for
RunQueryResponse, I note that thedocumentfield description says:Response fields:
transactionfield can only be set on the first response in the stream.read_timedoesn't seem sensible if there is no document.skipped_results: I guess the back end could send a document-less response with this field set as a "still skipping" notification?tseaver commentedon Jan 23, 2019
Looking at
Query.get, which loops over the stream ofRunQueryResponsemessages, ISTM that we could just not raise the error for the empty document. In fact, the whole thing could be simplified to the following, given that we don't return theskipped_resultsanywhere:I don't think raising exceptions about potential error cases from the back-end (non-empty response after empty first response, empty response after non-empty response) is useful here, given that we know the back end can return the empty response beyond the first one.
tseaver commentedon Jan 23, 2019
@KiwiPolarBear I'm sorry this issue has been frustrating. Could you try the patch in PR #7206 and see if it resolves your issue?
hishnash commentedon Jan 23, 2019
@tseaver I have been able to test that branch I can confirm the bug seems fixed
for at least offset sizes of upto 8500 (with limit = 100) (that is the largest single collection I have in my current data set)
it also appears to return the same set of items as using the
start_afterwith aDocumentSnapshotRemove bogus error checking of query response stream. (#7206)
Remove bogus error checking of query response stream. (#7206)