Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: treat None cursors as a no-op. #440

Merged
merged 4 commits into from Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion google/cloud/firestore_v1/base_query.py
Expand Up @@ -755,7 +755,7 @@ def _normalize_cursor(self, cursor, orders) -> Optional[Tuple[Any, Any]]:

document_fields = values

if len(document_fields) > len(orders):
if document_fields and len(document_fields) > len(orders):
msg = _MISMATCH_CURSOR_W_ORDER_BY.format(document_fields, order_keys)
raise ValueError(msg)

Expand Down
8 changes: 8 additions & 0 deletions tests/unit/v1/test_base_query.py
Expand Up @@ -726,6 +726,14 @@ def test__normalize_orders_wo_orders_w_snapshot_cursor_w_neq_where(self):
]
self.assertEqual(query._normalize_orders(), expected)

def test__normalize_orders_w_name_orders_w_none_cursor(self):
collection = self._make_collection("here")
query = (
self._make_one(collection).order_by("__name__", "DESCENDING").start_at(None)
)
expected = [query._make_order("__name__", "DESCENDING")]
self.assertEqual(query._normalize_orders(), expected)

def test__normalize_cursor_none(self):
query = self._make_one(mock.sentinel.parent)
self.assertIsNone(query._normalize_cursor(None, query._orders))
Expand Down