Skip to content

Library raises when fewer cursors than order by clauses #339

@crwilcox

Description

@crwilcox

Firestore supports setting multiple order by clauses, but then only using one of them for a cursor.
https://cloud.google.com/firestore/docs/query-data/query-cursors#set_cursor_based_on_multiple_fields

    def test__normalize_cursor_as_dict_extra_orders_ok(self):
        cursor = ({'name': 'Springfield'}, True)
        query = self._make_one(mock.sentinel.parent).order_by("name").order_by("state")

        query._normalize_cursor(cursor, query._orders)

also, I'd expect unnamed cursors to work, as they do in java for instance

 def test__normalize_cursor_extra_orders_ok(self):
        cursor = (['Springfield'], True)
        query = self._make_one(mock.sentinel.parent).order_by("name").order_by("state")

        query._normalize_cursor(cursor, query._orders)

Today, this raises the following error:

ValueError: The "order by" field path 'state' is not present in the cursor data {'name': 'Springfield'}. All fields sent to order_by() must be present in the fields if passed to one of start_at() / start_after() / end_before() / end_at() to define a cursor.

Open Question: Is this against the rules (cursor on something not ordered?

cursor = ({"a": 1}, True)
query = self._make_one(mock.sentinel.parent).order_by("b", "ASCENDING")

Metadata

Metadata

Assignees

Labels

api: firestoreIssues related to the googleapis/python-firestore API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions