Created
August 1, 2019 20:54
-
-
Save tseaver/f23119dd18f88fe5c06937c687a51282 to your computer and use it in GitHub Desktop.
Reproducer for google-cloud-python #7756
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from google.cloud.firestore_v1 import Client | |
def cleanup(coll): | |
for doc in coll.list_documents(): | |
print("Removing: {}".format(doc.path)) | |
doc.delete() | |
def initialize(coll): | |
for index in range(100): | |
doc = coll.document('test_{:09d}'.format(index)) | |
data = { | |
'count': 10 * index, | |
'wordcount': { | |
'page1': index * 10 + 100, | |
}, | |
} | |
print("Setting: {}".format(doc.path)) | |
doc.set(data) | |
def main(client): | |
coll = client.collection('gcp-7756') | |
if '--reinit' in sys.argv: | |
cleanup(coll) | |
initialize(coll) | |
for snapshot in coll.order_by('wordcount.page1').limit(3).stream(): | |
last_value = snapshot.get('wordcount.page1') | |
good_cursor = { | |
'wordcount': { | |
'page1': last_value | |
} | |
} | |
found = list(coll.order_by('wordcount.page1').start_after(good_cursor).limit(3).stream()) | |
bad_cursor = {'wordcount.page1': last_value} | |
# Will fail: | |
try: | |
list(coll.order_by('wordcount.page1').start_after(bad_cursor).limit(3).stream()) | |
except ValueError as exc: | |
print(exc) | |
else: | |
assert False, "Shouldn't succeed" | |
if __name__ == '__main__': | |
client = Client() | |
main(client) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment