Skip to content

Commit

Permalink
Fix sorting 'delete_changes' in 'Watch._compute_snapshot'. (#8809)
Browse files Browse the repository at this point in the history
  • Loading branch information
liamuk authored and tseaver committed Aug 1, 2019
1 parent ee416c9 commit c9b9c9d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion firestore/google/cloud/firestore_v1/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ def modify_doc(new_document, updated_tree, updated_map):
key = functools.cmp_to_key(self._comparator)

# Deletes are sorted based on the order of the existing document.
delete_changes = sorted(delete_changes, key=key)
delete_changes = sorted(delete_changes)
for name in delete_changes:
change, updated_tree, updated_map = delete_doc(
name, updated_tree, updated_map
Expand Down
22 changes: 22 additions & 0 deletions firestore/tests/unit/v1/test_watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,28 @@ class DummyDoc(object):
)
self.assertEqual(updated_map, doc_map) # no change

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

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=object())
updated_tree, updated_map, applied_changes = inst._compute_snapshot(
doc_tree, doc_map, delete_changes, add_changes, update_changes
)
self.assertEqual(updated_map, {})

def test__reset_docs(self):
from google.cloud.firestore_v1.watch import ChangeType

Expand Down

0 comments on commit c9b9c9d

Please sign in to comment.