Skip to content

Commit be98897

Browse files
fix: name parameter to indicate snapshot support (#169)
See #56
1 parent d4a0f81 commit be98897

File tree

1 file changed

+37
-31
lines changed

1 file changed

+37
-31
lines changed

‎google/cloud/firestore_v1/base_query.py

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def offset(self, num_to_skip) -> "BaseQuery":
443443
all_descendants=self._all_descendants,
444444
)
445445

446-
def _check_snapshot(self, document_fields) -> None:
446+
def _check_snapshot(self, document_snapshot) -> None:
447447
"""Validate local snapshots for non-collection-group queries.
448448
449449
Raises:
@@ -453,26 +453,26 @@ def _check_snapshot(self, document_fields) -> None:
453453
if self._all_descendants:
454454
return
455455

456-
if document_fields.reference._path[:-1] != self._parent._path:
456+
if document_snapshot.reference._path[:-1] != self._parent._path:
457457
raise ValueError("Cannot use snapshot from another collection as a cursor.")
458458

459-
def _cursor_helper(self, document_fields, before, start) -> "BaseQuery":
459+
def _cursor_helper(self, document_fields_or_snapshot, before, start) -> "BaseQuery":
460460
"""Set values to be used for a ``start_at`` or ``end_at`` cursor.
461461
462462
The values will later be used in a query protobuf.
463463
464-
When the query is sent to the server, the ``document_fields`` will
464+
When the query is sent to the server, the ``document_fields_or_snapshot`` will
465465
be used in the order given by fields set by
466466
:meth:`~google.cloud.firestore_v1.query.Query.order_by`.
467467
468468
Args:
469-
document_fields
469+
document_fields_or_snapshot
470470
(Union[:class:`~google.cloud.firestore_v1.document.DocumentSnapshot`, dict, list, tuple]):
471471
a document snapshot or a dictionary/list/tuple of fields
472472
representing a query results cursor. A cursor is a collection
473473
of values that represent a position in a query result set.
474474
before (bool): Flag indicating if the document in
475-
``document_fields`` should (:data:`False`) or
475+
``document_fields_or_snapshot`` should (:data:`False`) or
476476
shouldn't (:data:`True`) be included in the result set.
477477
start (Optional[bool]): determines if the cursor is a ``start_at``
478478
cursor (:data:`True`) or an ``end_at`` cursor (:data:`False`).
@@ -482,15 +482,15 @@ def _cursor_helper(self, document_fields, before, start) -> "BaseQuery":
482482
A query with cursor. Acts as a copy of the current query, modified
483483
with the newly added "start at" cursor.
484484
"""
485-
if isinstance(document_fields, tuple):
486-
document_fields = list(document_fields)
487-
elif isinstance(document_fields, document.DocumentSnapshot):
488-
self._check_snapshot(document_fields)
485+
if isinstance(document_fields_or_snapshot, tuple):
486+
document_fields_or_snapshot = list(document_fields_or_snapshot)
487+
elif isinstance(document_fields_or_snapshot, document.DocumentSnapshot):
488+
self._check_snapshot(document_fields_or_snapshot)
489489
else:
490490
# NOTE: We copy so that the caller can't modify after calling.
491-
document_fields = copy.deepcopy(document_fields)
491+
document_fields_or_snapshot = copy.deepcopy(document_fields_or_snapshot)
492492

493-
cursor_pair = document_fields, before
493+
cursor_pair = document_fields_or_snapshot, before
494494
query_kwargs = {
495495
"projection": self._projection,
496496
"field_filters": self._field_filters,
@@ -508,11 +508,11 @@ def _cursor_helper(self, document_fields, before, start) -> "BaseQuery":
508508

509509
return self.__class__(self._parent, **query_kwargs)
510510

511-
def start_at(self, document_fields) -> "BaseQuery":
511+
def start_at(self, document_fields_or_snapshot) -> "BaseQuery":
512512
"""Start query results at a particular document value.
513513
514514
The result set will **include** the document specified by
515-
``document_fields``.
515+
``document_fields_or_snapshot``.
516516
517517
If the current query already has specified a start cursor -- either
518518
via this method or
@@ -524,7 +524,7 @@ def start_at(self, document_fields) -> "BaseQuery":
524524
:meth:`~google.cloud.firestore_v1.query.Query.order_by`.
525525
526526
Args:
527-
document_fields
527+
document_fields_or_snapshot
528528
(Union[:class:`~google.cloud.firestore_v1.document.DocumentSnapshot`, dict, list, tuple]):
529529
a document snapshot or a dictionary/list/tuple of fields
530530
representing a query results cursor. A cursor is a collection
@@ -536,25 +536,25 @@ def start_at(self, document_fields) -> "BaseQuery":
536536
a copy of the current query, modified with the newly added
537537
"start at" cursor.
538538
"""
539-
return self._cursor_helper(document_fields, before=True, start=True)
539+
return self._cursor_helper(document_fields_or_snapshot, before=True, start=True)
540540

541-
def start_after(self, document_fields) -> "BaseQuery":
541+
def start_after(self, document_fields_or_snapshot) -> "BaseQuery":
542542
"""Start query results after a particular document value.
543543
544544
The result set will **exclude** the document specified by
545-
``document_fields``.
545+
``document_fields_or_snapshot``.
546546
547547
If the current query already has specified a start cursor -- either
548548
via this method or
549549
:meth:`~google.cloud.firestore_v1.query.Query.start_at` -- this will
550550
overwrite it.
551551
552-
When the query is sent to the server, the ``document_fields`` will
552+
When the query is sent to the server, the ``document_fields_or_snapshot`` will
553553
be used in the order given by fields set by
554554
:meth:`~google.cloud.firestore_v1.query.Query.order_by`.
555555
556556
Args:
557-
document_fields
557+
document_fields_or_snapshot
558558
(Union[:class:`~google.cloud.firestore_v1.document.DocumentSnapshot`, dict, list, tuple]):
559559
a document snapshot or a dictionary/list/tuple of fields
560560
representing a query results cursor. A cursor is a collection
@@ -565,25 +565,27 @@ def start_after(self, document_fields) -> "BaseQuery":
565565
A query with cursor. Acts as a copy of the current query, modified
566566
with the newly added "start after" cursor.
567567
"""
568-
return self._cursor_helper(document_fields, before=False, start=True)
568+
return self._cursor_helper(
569+
document_fields_or_snapshot, before=False, start=True
570+
)
569571

570-
def end_before(self, document_fields) -> "BaseQuery":
572+
def end_before(self, document_fields_or_snapshot) -> "BaseQuery":
571573
"""End query results before a particular document value.
572574
573575
The result set will **exclude** the document specified by
574-
``document_fields``.
576+
``document_fields_or_snapshot``.
575577
576578
If the current query already has specified an end cursor -- either
577579
via this method or
578580
:meth:`~google.cloud.firestore_v1.query.Query.end_at` -- this will
579581
overwrite it.
580582
581-
When the query is sent to the server, the ``document_fields`` will
583+
When the query is sent to the server, the ``document_fields_or_snapshot`` will
582584
be used in the order given by fields set by
583585
:meth:`~google.cloud.firestore_v1.query.Query.order_by`.
584586
585587
Args:
586-
document_fields
588+
document_fields_or_snapshot
587589
(Union[:class:`~google.cloud.firestore_v1.document.DocumentSnapshot`, dict, list, tuple]):
588590
a document snapshot or a dictionary/list/tuple of fields
589591
representing a query results cursor. A cursor is a collection
@@ -594,25 +596,27 @@ def end_before(self, document_fields) -> "BaseQuery":
594596
A query with cursor. Acts as a copy of the current query, modified
595597
with the newly added "end before" cursor.
596598
"""
597-
return self._cursor_helper(document_fields, before=True, start=False)
599+
return self._cursor_helper(
600+
document_fields_or_snapshot, before=True, start=False
601+
)
598602

599-
def end_at(self, document_fields) -> "BaseQuery":
603+
def end_at(self, document_fields_or_snapshot) -> "BaseQuery":
600604
"""End query results at a particular document value.
601605
602606
The result set will **include** the document specified by
603-
``document_fields``.
607+
``document_fields_or_snapshot``.
604608
605609
If the current query already has specified an end cursor -- either
606610
via this method or
607611
:meth:`~google.cloud.firestore_v1.query.Query.end_before` -- this will
608612
overwrite it.
609613
610-
When the query is sent to the server, the ``document_fields`` will
614+
When the query is sent to the server, the ``document_fields_or_snapshot`` will
611615
be used in the order given by fields set by
612616
:meth:`~google.cloud.firestore_v1.query.Query.order_by`.
613617
614618
Args:
615-
document_fields
619+
document_fields_or_snapshot
616620
(Union[:class:`~google.cloud.firestore_v1.document.DocumentSnapshot`, dict, list, tuple]):
617621
a document snapshot or a dictionary/list/tuple of fields
618622
representing a query results cursor. A cursor is a collection
@@ -623,7 +627,9 @@ def end_at(self, document_fields) -> "BaseQuery":
623627
A query with cursor. Acts as a copy of the current query, modified
624628
with the newly added "end at" cursor.
625629
"""
626-
return self._cursor_helper(document_fields, before=False, start=False)
630+
return self._cursor_helper(
631+
document_fields_or_snapshot, before=False, start=False
632+
)
627633

628634
def _filters_pb(self) -> Any:
629635
"""Convert all the filters into a single generic Filter protobuf.

0 commit comments

Comments
 (0)