Skip to content

Commit c97a168

Browse files
fix(firestore): use specific naming convention (#58)
Co-authored-by: Christopher Wilcox <crwilcox@google.com>
1 parent 8c75e21 commit c97a168

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

‎google/cloud/firestore_v1/query.py

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ def offset(self, num_to_skip):
439439
all_descendants=self._all_descendants,
440440
)
441441

442-
def _check_snapshot(self, document_fields):
442+
def _check_snapshot(self, document_snapshot):
443443
"""Validate local snapshots for non-collection-group queries.
444444
445445
Raises:
@@ -449,26 +449,26 @@ def _check_snapshot(self, document_fields):
449449
if self._all_descendants:
450450
return
451451

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

455-
def _cursor_helper(self, document_fields, before, start):
455+
def _cursor_helper(self, document_fields_or_snapshot, before, start):
456456
"""Set values to be used for a ``start_at`` or ``end_at`` cursor.
457457
458458
The values will later be used in a query protobuf.
459459
460-
When the query is sent to the server, the ``document_fields`` will
460+
When the query is sent to the server, the ``document_fields_or_snapshot`` will
461461
be used in the order given by fields set by
462462
:meth:`~google.cloud.firestore_v1.query.Query.order_by`.
463463
464464
Args:
465-
document_fields
465+
document_fields_or_snapshot
466466
(Union[:class:`~google.cloud.firestore_v1.document.DocumentSnapshot`, dict, list, tuple]):
467467
a document snapshot or a dictionary/list/tuple of fields
468468
representing a query results cursor. A cursor is a collection
469469
of values that represent a position in a query result set.
470470
before (bool): Flag indicating if the document in
471-
``document_fields`` should (:data:`False`) or
471+
``document_fields_or_snapshot`` should (:data:`False`) or
472472
shouldn't (:data:`True`) be included in the result set.
473473
start (Optional[bool]): determines if the cursor is a ``start_at``
474474
cursor (:data:`True`) or an ``end_at`` cursor (:data:`False`).
@@ -478,15 +478,15 @@ def _cursor_helper(self, document_fields, before, start):
478478
A query with cursor. Acts as a copy of the current query, modified
479479
with the newly added "start at" cursor.
480480
"""
481-
if isinstance(document_fields, tuple):
482-
document_fields = list(document_fields)
483-
elif isinstance(document_fields, document.DocumentSnapshot):
484-
self._check_snapshot(document_fields)
481+
if isinstance(document_fields_or_snapshot, tuple):
482+
document_fields_or_snapshot = list(document_fields_or_snapshot)
483+
elif isinstance(document_fields_or_snapshot, document.DocumentSnapshot):
484+
self._check_snapshot(document_fields_or_snapshot)
485485
else:
486486
# NOTE: We copy so that the caller can't modify after calling.
487-
document_fields = copy.deepcopy(document_fields)
487+
document_fields_or_snapshot = copy.deepcopy(document_fields_or_snapshot)
488488

489-
cursor_pair = document_fields, before
489+
cursor_pair = document_fields_or_snapshot, before
490490
query_kwargs = {
491491
"projection": self._projection,
492492
"field_filters": self._field_filters,
@@ -504,23 +504,23 @@ def _cursor_helper(self, document_fields, before, start):
504504

505505
return self.__class__(self._parent, **query_kwargs)
506506

507-
def start_at(self, document_fields):
507+
def start_at(self, document_fields_or_snapshot):
508508
"""Start query results at a particular document value.
509509
510510
The result set will **include** the document specified by
511-
``document_fields``.
511+
``document_fields_or_snapshot``.
512512
513513
If the current query already has specified a start cursor -- either
514514
via this method or
515515
:meth:`~google.cloud.firestore_v1.query.Query.start_after` -- this
516516
will overwrite it.
517517
518-
When the query is sent to the server, the ``document_fields`` will
518+
When the query is sent to the server, the ``document_fields_or_snapshot`` will
519519
be used in the order given by fields set by
520520
:meth:`~google.cloud.firestore_v1.query.Query.order_by`.
521521
522522
Args:
523-
document_fields
523+
document_fields_or_snapshot
524524
(Union[:class:`~google.cloud.firestore_v1.document.DocumentSnapshot`, dict, list, tuple]):
525525
a document snapshot or a dictionary/list/tuple of fields
526526
representing a query results cursor. A cursor is a collection
@@ -532,25 +532,25 @@ def start_at(self, document_fields):
532532
a copy of the current query, modified with the newly added
533533
"start at" cursor.
534534
"""
535-
return self._cursor_helper(document_fields, before=True, start=True)
535+
return self._cursor_helper(document_fields_or_snapshot, before=True, start=True)
536536

537-
def start_after(self, document_fields):
537+
def start_after(self, document_fields_or_snapshot):
538538
"""Start query results after a particular document value.
539539
540540
The result set will **exclude** the document specified by
541-
``document_fields``.
541+
``document_fields_or_snapshot``.
542542
543543
If the current query already has specified a start cursor -- either
544544
via this method or
545545
:meth:`~google.cloud.firestore_v1.query.Query.start_at` -- this will
546546
overwrite it.
547547
548-
When the query is sent to the server, the ``document_fields`` will
548+
When the query is sent to the server, the ``document_fields_or_snapshot`` will
549549
be used in the order given by fields set by
550550
:meth:`~google.cloud.firestore_v1.query.Query.order_by`.
551551
552552
Args:
553-
document_fields
553+
document_fields_or_snapshot
554554
(Union[:class:`~google.cloud.firestore_v1.document.DocumentSnapshot`, dict, list, tuple]):
555555
a document snapshot or a dictionary/list/tuple of fields
556556
representing a query results cursor. A cursor is a collection
@@ -561,25 +561,27 @@ def start_after(self, document_fields):
561561
A query with cursor. Acts as a copy of the current query, modified
562562
with the newly added "start after" cursor.
563563
"""
564-
return self._cursor_helper(document_fields, before=False, start=True)
564+
return self._cursor_helper(
565+
document_fields_or_snapshot, before=False, start=True
566+
)
565567

566-
def end_before(self, document_fields):
568+
def end_before(self, document_fields_or_snapshot):
567569
"""End query results before a particular document value.
568570
569571
The result set will **exclude** the document specified by
570-
``document_fields``.
572+
``document_fields_or_snapshot``.
571573
572574
If the current query already has specified an end cursor -- either
573575
via this method or
574576
:meth:`~google.cloud.firestore_v1.query.Query.end_at` -- this will
575577
overwrite it.
576578
577-
When the query is sent to the server, the ``document_fields`` will
579+
When the query is sent to the server, the ``document_fields_or_snapshot`` will
578580
be used in the order given by fields set by
579581
:meth:`~google.cloud.firestore_v1.query.Query.order_by`.
580582
581583
Args:
582-
document_fields
584+
document_fields_or_snapshot
583585
(Union[:class:`~google.cloud.firestore_v1.document.DocumentSnapshot`, dict, list, tuple]):
584586
a document snapshot or a dictionary/list/tuple of fields
585587
representing a query results cursor. A cursor is a collection
@@ -590,25 +592,27 @@ def end_before(self, document_fields):
590592
A query with cursor. Acts as a copy of the current query, modified
591593
with the newly added "end before" cursor.
592594
"""
593-
return self._cursor_helper(document_fields, before=True, start=False)
595+
return self._cursor_helper(
596+
document_fields_or_snapshot, before=True, start=False
597+
)
594598

595-
def end_at(self, document_fields):
599+
def end_at(self, document_fields_or_snapshot):
596600
"""End query results at a particular document value.
597601
598602
The result set will **include** the document specified by
599-
``document_fields``.
603+
``document_fields_or_snapshot``.
600604
601605
If the current query already has specified an end cursor -- either
602606
via this method or
603607
:meth:`~google.cloud.firestore_v1.query.Query.end_before` -- this will
604608
overwrite it.
605609
606-
When the query is sent to the server, the ``document_fields`` will
610+
When the query is sent to the server, the ``document_fields_or_snapshot`` will
607611
be used in the order given by fields set by
608612
:meth:`~google.cloud.firestore_v1.query.Query.order_by`.
609613
610614
Args:
611-
document_fields
615+
document_fields_or_snapshot
612616
(Union[:class:`~google.cloud.firestore_v1.document.DocumentSnapshot`, dict, list, tuple]):
613617
a document snapshot or a dictionary/list/tuple of fields
614618
representing a query results cursor. A cursor is a collection
@@ -619,7 +623,9 @@ def end_at(self, document_fields):
619623
A query with cursor. Acts as a copy of the current query, modified
620624
with the newly added "end at" cursor.
621625
"""
622-
return self._cursor_helper(document_fields, before=False, start=False)
626+
return self._cursor_helper(
627+
document_fields_or_snapshot, before=False, start=False
628+
)
623629

624630
def _filters_pb(self):
625631
"""Convert all the filters into a single generic Filter protobuf.

0 commit comments

Comments
 (0)