Skip to content

Commit

Permalink
fix: treat None cursors as a no-op. (#440)
Browse files Browse the repository at this point in the history
start_at(None) was causing an error. Address that and treat this as a no-op
  • Loading branch information
crwilcox committed Sep 2, 2021
1 parent 9316cce commit e7aed0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
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

0 comments on commit e7aed0f

Please sign in to comment.