-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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: Fix sorting 'delete_changes' in 'Watch._compute_snapshot'. #8809
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@liamuk Thanks for the patch! Our tests are passing here because they do not exercise Watch._compute_snapshot
on an instance with a non-dummy comparator. Can you please add a test to the TestWatch
class tests/unit/v1/test_watch.py
which exercises that case? E.g.:
def test__compute_snapshot_deletes_w_real_comparator(self):
from google.cloud.firestore_v1.watch import WatchDocTree
doc_tree = WatchDocTree()
class DummyDoc(object):
update_time = mock.sentinel
def _comparator(doc1, doc2):
if doc1.field > doc2.field:
return 1
if doc1.field < doc2.field:
return -1
return 0
deleted_doc_1 = DummyDoc()
deleted_doc_2 = DummyDoc()
doc_tree = doc_tree.insert(deleted_doc_1, None)
doc_tree = doc_tree.insert(deleted_doc_2, None)
doc_map = {
"/deleted_1": deleted_doc_1,
"/deleted_2": deleted_doc_2,
}
delete_changes = ["/deleted_1", "/deleted_2"]
add_changes = []
update_changes = []
inst = self._makeOne(comparator=_comparator)
updated_tree, updated_map, applied_changes = inst._compute_snapshot(
doc_tree, doc_map, delete_changes, add_changes, update_changes
)
self.assertEqual(updated_map, {})
Added that test verbatim |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry to have to ask for changes in the code I suggested: I checked that the test ran and failed without your patch, but not that it appeased coverage / lint checkers.
Changed those two things, and also added you as a collaborator to the patch's fork in case anything else comes up. You writing code for me to copy into the patch branch isn't the most efficient process haha. |
The Video Intelligence failure is due to a Kokoro glitch: "Cannot check out non-mergeable pull request as if merged." |
@liamuk Thanks again for the patch! |
delete_changes
on the changed line is a list of string, not a list of DocumentSnapshots, so it should not be sorted with the query comparator function (see https://github.com/googleapis/google-cloud-python/blob/master/firestore/google/cloud/firestore_v1/watch.py#L575)For context, I'm getting this error in one of my snapshot listeners in google-cloud-firestore==1.3.0