Repository: googleapis/google-cloud-python

Issue:
Firestore: 'Query.order_by("__name__")' implies converting field values to extended paths.
Per the `query-cursor-vals-docid` conformance test.  

```python
query = collection.order_by('__name__').start_at(['a']).end_at(['z'])
```

The  `'a'` should be converted to `/projects/<project-id>/databases/<database>/<collection_path>/a`;  likewise the `z`.


Discussion:

Resolving patch:
diff --git a/firestore/google/cloud/firestore_v1beta1/query.py b/firestore/google/cloud/firestore_v1beta1/query.py
--- a/firestore/google/cloud/firestore_v1beta1/query.py
+++ b/firestore/google/cloud/firestore_v1beta1/query.py
@@ -563,8 +563,7 @@ def _normalize_projection(projection):
 
         return projection
 
-    @staticmethod
-    def _normalize_cursor(cursor, orders):
+    def _normalize_cursor(self, cursor, orders):
         """Helper: convert cursor to a list of values based on orders."""
         if cursor is None:
             return
@@ -593,11 +592,19 @@ def _normalize_cursor(cursor, orders):
             raise ValueError(msg)
 
         _transform_bases = (transforms.Sentinel, transforms._ValueList)
-        for field in document_fields:
+
+        for index, key_field in enumerate(zip(order_keys, document_fields)):
+            key, field = key_field
+
             if isinstance(field, _transform_bases):
                 msg = _INVALID_CURSOR_TRANSFORM
                 raise ValueError(msg)
 
+            if key == "__name__" and "/" not in field:
+                document_fields[index] = "{}/{}/{}".format(
+                    self._client._database_string, "/".join(self._parent._path), field
+                )
+
         return document_fields, before
 
     def _to_protobuf(self):


Test patch:
diff --git a/firestore/tests/unit/test_query.py b/firestore/tests/unit/test_query.py
--- a/firestore/tests/unit/test_query.py
+++ b/firestore/tests/unit/test_query.py
@@ -603,6 +603,36 @@ def test__normalize_cursor_as_dict_hit(self):
 
         self.assertEqual(query._normalize_cursor(cursor, query._orders), ([1], True))
 
+    def test__normalize_cursor_w___name___w_slash(self):
+        db_string = "projects/my-project/database/(default)"
+        client = mock.Mock(spec=["_database_string"])
+        client._database_string = db_string
+        parent = mock.Mock(spec=["_path", "_client"])
+        parent._client = client
+        parent._path = ["C"]
+        query = self._make_one(parent).order_by("__name__", "ASCENDING")
+        expected = "{}/C/b".format(db_string)
+        cursor = ([expected], True)
+
+        self.assertEqual(
+            query._normalize_cursor(cursor, query._orders), ([expected], True)
+        )
+
+    def test__normalize_cursor_w___name___wo_slash(self):
+        db_string = "projects/my-project/database/(default)"
+        client = mock.Mock(spec=["_database_string"])
+        client._database_string = db_string
+        parent = mock.Mock(spec=["_path", "_client"])
+        parent._client = client
+        parent._path = ["C"]
+        query = self._make_one(parent).order_by("__name__", "ASCENDING")
+        cursor = (["b"], True)
+        expected = "{}/C/b".format(db_string)
+
+        self.assertEqual(
+            query._normalize_cursor(cursor, query._orders), ([expected], True)
+        )
+
     def test__to_protobuf_all_fields(self):
         from google.protobuf import wrappers_pb2
         from google.cloud.firestore_v1beta1.gapic import enums