Skip to content

Commit

Permalink
Treat 'None' as EOF in 'Watch.on_snapshot'. (#8687)
Browse files Browse the repository at this point in the history
  • Loading branch information
tseaver authored Jul 24, 2019
1 parent f30c4de commit 1dc92c7
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 71 deletions.
31 changes: 18 additions & 13 deletions firestore/google/cloud/firestore_v1/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,12 @@ def on_snapshot(self, proto):
TargetChange.CURRENT: self._on_snapshot_target_change_current,
}

target_change = proto.target_change
target_change = getattr(proto, "target_change", "")
document_change = getattr(proto, "document_change", "")
document_delete = getattr(proto, "document_delete", "")
document_remove = getattr(proto, "document_remove", "")
filter_ = getattr(proto, "filter", "")

if str(target_change):
target_change_type = target_change.target_change_type
_LOGGER.debug("on_snapshot: target change: " + str(target_change_type))
Expand All @@ -449,13 +454,13 @@ def on_snapshot(self, proto):
# in other implementations, such as node, the backoff is reset here
# in this version bidi rpc is just used and will control this.

elif str(proto.document_change):
elif str(document_change):
_LOGGER.debug("on_snapshot: document change")

# No other target_ids can show up here, but we still need to see
# if the targetId was in the added list or removed list.
target_ids = proto.document_change.target_ids or []
removed_target_ids = proto.document_change.removed_target_ids or []
target_ids = document_change.target_ids or []
removed_target_ids = document_change.removed_target_ids or []
changed = False
removed = False

Expand All @@ -468,8 +473,6 @@ def on_snapshot(self, proto):
if changed:
_LOGGER.debug("on_snapshot: document change: CHANGED")

# google.cloud.firestore_v1.types.DocumentChange
document_change = proto.document_change
# google.cloud.firestore_v1.types.Document
document = document_change.document

Expand Down Expand Up @@ -498,31 +501,33 @@ def on_snapshot(self, proto):

elif removed:
_LOGGER.debug("on_snapshot: document change: REMOVED")
document = proto.document_change.document
document = document_change.document
self.change_map[document.name] = ChangeType.REMOVED

# NB: document_delete and document_remove (as far as we, the client,
# are concerned) are functionally equivalent

elif str(proto.document_delete):
elif str(document_delete):
_LOGGER.debug("on_snapshot: document change: DELETE")
name = proto.document_delete.document
name = document_delete.document
self.change_map[name] = ChangeType.REMOVED

elif str(proto.document_remove):
elif str(document_remove):
_LOGGER.debug("on_snapshot: document change: REMOVE")
name = proto.document_remove.document
name = document_remove.document
self.change_map[name] = ChangeType.REMOVED

elif proto.filter:
elif filter_:
_LOGGER.debug("on_snapshot: filter update")
if proto.filter.count != self._current_size():
if filter_.count != self._current_size():
# We need to remove all the current results.
self._reset_docs()
# The filter didn't match, so re-issue the query.
# TODO: reset stream method?
# self._reset_stream();

elif proto is None:
self.close()
else:
_LOGGER.debug("UNKNOWN TYPE. UHOH")
self.close(reason=ValueError("Unknown listen response type: %s" % proto))
Expand Down
4 changes: 2 additions & 2 deletions firestore/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ def system(session):

# Run py.test against the system tests.
if system_test_exists:
session.run("py.test", "--quiet", system_test_path, *session.posargs)
session.run("py.test", "--verbose", system_test_path, *session.posargs)
if system_test_folder_exists:
session.run("py.test", "--quiet", system_test_folder_path, *session.posargs)
session.run("py.test", "--verbose", system_test_folder_path, *session.posargs)


@nox.session(python="3.7")
Expand Down
Loading

0 comments on commit 1dc92c7

Please sign in to comment.