Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a6f220e

Browse files
authored
Treat 'None' as EOF in 'Watch.on_snapshot'. (#8687)
See: googleapis/google-cloud-python#8650 (review)
1 parent 1908973 commit a6f220e

File tree

5 files changed

+118
-71
lines changed

5 files changed

+118
-71
lines changed

google/cloud/firestore_v1/watch.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,12 @@ def on_snapshot(self, proto):
426426
TargetChange.CURRENT: self._on_snapshot_target_change_current,
427427
}
428428

429-
target_change = proto.target_change
429+
target_change = getattr(proto, "target_change", "")
430+
document_change = getattr(proto, "document_change", "")
431+
document_delete = getattr(proto, "document_delete", "")
432+
document_remove = getattr(proto, "document_remove", "")
433+
filter_ = getattr(proto, "filter", "")
434+
430435
if str(target_change):
431436
target_change_type = target_change.target_change_type
432437
_LOGGER.debug("on_snapshot: target change: " + str(target_change_type))
@@ -449,13 +454,13 @@ def on_snapshot(self, proto):
449454
# in other implementations, such as node, the backoff is reset here
450455
# in this version bidi rpc is just used and will control this.
451456

452-
elif str(proto.document_change):
457+
elif str(document_change):
453458
_LOGGER.debug("on_snapshot: document change")
454459

455460
# No other target_ids can show up here, but we still need to see
456461
# if the targetId was in the added list or removed list.
457-
target_ids = proto.document_change.target_ids or []
458-
removed_target_ids = proto.document_change.removed_target_ids or []
462+
target_ids = document_change.target_ids or []
463+
removed_target_ids = document_change.removed_target_ids or []
459464
changed = False
460465
removed = False
461466

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

471-
# google.cloud.firestore_v1.types.DocumentChange
472-
document_change = proto.document_change
473476
# google.cloud.firestore_v1.types.Document
474477
document = document_change.document
475478

@@ -498,31 +501,33 @@ def on_snapshot(self, proto):
498501

499502
elif removed:
500503
_LOGGER.debug("on_snapshot: document change: REMOVED")
501-
document = proto.document_change.document
504+
document = document_change.document
502505
self.change_map[document.name] = ChangeType.REMOVED
503506

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

507-
elif str(proto.document_delete):
510+
elif str(document_delete):
508511
_LOGGER.debug("on_snapshot: document change: DELETE")
509-
name = proto.document_delete.document
512+
name = document_delete.document
510513
self.change_map[name] = ChangeType.REMOVED
511514

512-
elif str(proto.document_remove):
515+
elif str(document_remove):
513516
_LOGGER.debug("on_snapshot: document change: REMOVE")
514-
name = proto.document_remove.document
517+
name = document_remove.document
515518
self.change_map[name] = ChangeType.REMOVED
516519

517-
elif proto.filter:
520+
elif filter_:
518521
_LOGGER.debug("on_snapshot: filter update")
519-
if proto.filter.count != self._current_size():
522+
if filter_.count != self._current_size():
520523
# We need to remove all the current results.
521524
self._reset_docs()
522525
# The filter didn't match, so re-issue the query.
523526
# TODO: reset stream method?
524527
# self._reset_stream();
525528

529+
elif proto is None:
530+
self.close()
526531
else:
527532
_LOGGER.debug("UNKNOWN TYPE. UHOH")
528533
self.close(reason=ValueError("Unknown listen response type: %s" % proto))

noxfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ def system(session):
120120

121121
# Run py.test against the system tests.
122122
if system_test_exists:
123-
session.run("py.test", "--quiet", system_test_path, *session.posargs)
123+
session.run("py.test", "--verbose", system_test_path, *session.posargs)
124124
if system_test_folder_exists:
125-
session.run("py.test", "--quiet", system_test_folder_path, *session.posargs)
125+
session.run("py.test", "--verbose", system_test_folder_path, *session.posargs)
126126

127127

128128
@nox.session(python="3.7")

0 commit comments

Comments
 (0)