Skip to content
This repository was archived by the owner on Mar 2, 2026. It is now read-only.

Commit 0bfc5e2

Browse files
committed
improved snapshot parsing
1 parent 313d660 commit 0bfc5e2

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

google/cloud/firestore_v1/base_query.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -929,9 +929,8 @@ def _normalize_cursor(self, cursor, orders) -> Tuple[List, bool] | None:
929929

930930
if isinstance(document_fields, document.DocumentSnapshot):
931931
snapshot = document_fields
932-
document_fields = snapshot.to_dict()
933-
if document_fields is not None:
934-
document_fields["__name__"] = snapshot.reference
932+
document_fields = copy.deepcopy(snapshot._data)
933+
document_fields["__name__"] = snapshot.reference
935934

936935
if isinstance(document_fields, dict):
937936
# Transform to list using orders

tests/unit/v1/test_base_query.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,16 @@ def test_basequery__normalize_cursor_as_snapshot_hit():
13991399

14001400
assert query._normalize_cursor(cursor, query._orders) == ([1], True)
14011401

1402+
def test_basequery__normalize_cursor_non_existant_snapshot():
1403+
from google.cloud.firestore_v1 import document
1404+
values = {"b": 1}
1405+
docref = _make_docref("here", "doc_id")
1406+
snapshot = document.DocumentSnapshot(docref, values, False, None, None, None)
1407+
cursor = (snapshot, True)
1408+
collection = _make_collection("here")
1409+
query = _make_base_query(collection).order_by("b", "ASCENDING")
1410+
1411+
assert query._normalize_cursor(cursor, query._orders) == ([1], True)
14021412

14031413
def test_basequery__normalize_cursor_w___name___w_reference():
14041414
db_string = "projects/my-project/database/(default)"

0 commit comments

Comments
 (0)