@@ -426,7 +426,12 @@ def on_snapshot(self, proto):
426
426
TargetChange .CURRENT : self ._on_snapshot_target_change_current ,
427
427
}
428
428
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
+
430
435
if str (target_change ):
431
436
target_change_type = target_change .target_change_type
432
437
_LOGGER .debug ("on_snapshot: target change: " + str (target_change_type ))
@@ -449,13 +454,13 @@ def on_snapshot(self, proto):
449
454
# in other implementations, such as node, the backoff is reset here
450
455
# in this version bidi rpc is just used and will control this.
451
456
452
- elif str (proto . document_change ):
457
+ elif str (document_change ):
453
458
_LOGGER .debug ("on_snapshot: document change" )
454
459
455
460
# No other target_ids can show up here, but we still need to see
456
461
# 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 []
459
464
changed = False
460
465
removed = False
461
466
@@ -468,8 +473,6 @@ def on_snapshot(self, proto):
468
473
if changed :
469
474
_LOGGER .debug ("on_snapshot: document change: CHANGED" )
470
475
471
- # google.cloud.firestore_v1.types.DocumentChange
472
- document_change = proto .document_change
473
476
# google.cloud.firestore_v1.types.Document
474
477
document = document_change .document
475
478
@@ -498,31 +501,33 @@ def on_snapshot(self, proto):
498
501
499
502
elif removed :
500
503
_LOGGER .debug ("on_snapshot: document change: REMOVED" )
501
- document = proto . document_change .document
504
+ document = document_change .document
502
505
self .change_map [document .name ] = ChangeType .REMOVED
503
506
504
507
# NB: document_delete and document_remove (as far as we, the client,
505
508
# are concerned) are functionally equivalent
506
509
507
- elif str (proto . document_delete ):
510
+ elif str (document_delete ):
508
511
_LOGGER .debug ("on_snapshot: document change: DELETE" )
509
- name = proto . document_delete .document
512
+ name = document_delete .document
510
513
self .change_map [name ] = ChangeType .REMOVED
511
514
512
- elif str (proto . document_remove ):
515
+ elif str (document_remove ):
513
516
_LOGGER .debug ("on_snapshot: document change: REMOVE" )
514
- name = proto . document_remove .document
517
+ name = document_remove .document
515
518
self .change_map [name ] = ChangeType .REMOVED
516
519
517
- elif proto . filter :
520
+ elif filter_ :
518
521
_LOGGER .debug ("on_snapshot: filter update" )
519
- if proto . filter .count != self ._current_size ():
522
+ if filter_ .count != self ._current_size ():
520
523
# We need to remove all the current results.
521
524
self ._reset_docs ()
522
525
# The filter didn't match, so re-issue the query.
523
526
# TODO: reset stream method?
524
527
# self._reset_stream();
525
528
529
+ elif proto is None :
530
+ self .close ()
526
531
else :
527
532
_LOGGER .debug ("UNKNOWN TYPE. UHOH" )
528
533
self .close (reason = ValueError ("Unknown listen response type: %s" % proto ))
0 commit comments