Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions google/cloud/firestore_v1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

# Copyright 2020 Google LLC
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,7 +47,7 @@
from google.cloud.firestore_v1.watch import Watch


# TODO(microgen): this is all on the generated surface. We require this to match
# TODO(https://github.com/googleapis/python-firestore/issues/93): this is all on the generated surface. We require this to match
# firestore.py. So comment out until needed on customer level for certain.
# from .services.firestore import FirestoreClient
# from .types.common import DocumentMask
Expand Down
3 changes: 2 additions & 1 deletion google/cloud/firestore_v1/base_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ def __eq__(self, other):
return self._reference == other._reference and self._data == other._data

def __hash__(self):
# TODO(microgen): maybe add datetime_with_nanos to protoplus, revisit
# TODO(microgen, https://github.com/googleapis/proto-plus-python/issues/38):
# maybe add datetime_with_nanos to protoplus, revisit
# seconds = self.update_time.seconds
# nanos = self.update_time.nanos
seconds = int(self.update_time.timestamp())
Expand Down
44 changes: 0 additions & 44 deletions google/cloud/firestore_v1/base_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,50 +778,6 @@ def _comparator(self, doc1, doc2):
return orderBy.direction * comp

return 0
_orders = self._orders

# Add implicit sorting by name, using the last specified direction.
if len(_orders) == 0:
lastDirection = BaseQuery.ASCENDING
else:
if _orders[-1].direction == 1:
lastDirection = BaseQuery.ASCENDING
else:
lastDirection = BaseQuery.DESCENDING

orderBys = list(_orders)

order_pb = query.StructuredQuery.Order(
field=query.StructuredQuery.FieldReference(field_path="id"),
direction=_enum_from_direction(lastDirection),
)
orderBys.append(order_pb)

for orderBy in orderBys:
if orderBy.field.field_path == "id":
# If ordering by docuent id, compare resource paths.
comp = Order()._compare_to(doc1.reference._path, doc2.reference._path)
else:
if (
orderBy.field.field_path not in doc1._data
or orderBy.field.field_path not in doc2._data
):
raise ValueError(
"Can only compare fields that exist in the "
"DocumentSnapshot. Please include the fields you are "
"ordering on in your select() call."
)
v1 = doc1._data[orderBy.field.field_path]
v2 = doc2._data[orderBy.field.field_path]
encoded_v1 = _helpers.encode_value(v1)
encoded_v2 = _helpers.encode_value(v2)
comp = Order().compare(encoded_v1, encoded_v2)

if comp != 0:
# 1 == Ascending, -1 == Descending
return orderBy.direction * comp

return 0


def _enum_from_op_string(op_string):
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/firestore_v1/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def get_all(self, references, field_paths=None, transaction=None):
for get_doc_response in response_iterator:
yield _parse_batch_get(get_doc_response, reference_map, self)

def collections(self,):
def collections(self):
"""List top-level collections of the client's database.

Returns:
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/firestore_v1/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def from_value(value):
}

if v not in lut:
raise ValueError("Could not detect value type for " + str(v))
raise ValueError(f"Could not detect value type for {v}")
return lut[v]


Expand Down Expand Up @@ -99,7 +99,7 @@ def compare(cls, left, right):
elif value_type == "map_value":
return cls.compare_objects(left, right)
else:
raise ValueError("Unknown ``value_type``", str(value_type))
raise ValueError(f"Unknown ``value_type`` {value_type}")

@staticmethod
def compare_blobs(left, right):
Expand Down
3 changes: 2 additions & 1 deletion google/cloud/firestore_v1beta1/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,8 @@ def __eq__(self, other):
return self._reference == other._reference and self._data == other._data

def __hash__(self):
# TODO(microgen): maybe add datetime_with_nanos to protoplus, revisit
# TODO(microgen, https://github.com/googleapis/proto-plus-python/issues/38):
# maybe add datetime_with_nanos to protoplus, revisit
# seconds = self.update_time.seconds
# nanos = self.update_time.nanos
seconds = int(self.update_time.timestamp())
Expand Down
24 changes: 12 additions & 12 deletions tests/unit/v1/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ def test_get(self, query_class):
get_response = collection.get()

query_class.assert_called_once_with(collection)
query_inst = query_class.return_value
self.assertIs(get_response, query_inst.stream.return_value)
query_inst.stream.assert_called_once_with(transaction=None)
query_instance = query_class.return_value
self.assertIs(get_response, query_instance.stream.return_value)
query_instance.stream.assert_called_once_with(transaction=None)

# Verify the deprecation
self.assertEqual(len(warned), 1)
Expand All @@ -279,9 +279,9 @@ def test_get_with_transaction(self, query_class):
get_response = collection.get(transaction=transaction)

query_class.assert_called_once_with(collection)
query_inst = query_class.return_value
self.assertIs(get_response, query_inst.stream.return_value)
query_inst.stream.assert_called_once_with(transaction=transaction)
query_instance = query_class.return_value
self.assertIs(get_response, query_instance.stream.return_value)
query_instance.stream.assert_called_once_with(transaction=transaction)

# Verify the deprecation
self.assertEqual(len(warned), 1)
Expand All @@ -293,9 +293,9 @@ def test_stream(self, query_class):
stream_response = collection.stream()

query_class.assert_called_once_with(collection)
query_inst = query_class.return_value
self.assertIs(stream_response, query_inst.stream.return_value)
query_inst.stream.assert_called_once_with(transaction=None)
query_instance = query_class.return_value
self.assertIs(stream_response, query_instance.stream.return_value)
query_instance.stream.assert_called_once_with(transaction=None)

@mock.patch("google.cloud.firestore_v1.query.Query", autospec=True)
def test_stream_with_transaction(self, query_class):
Expand All @@ -304,9 +304,9 @@ def test_stream_with_transaction(self, query_class):
stream_response = collection.stream(transaction=transaction)

query_class.assert_called_once_with(collection)
query_inst = query_class.return_value
self.assertIs(stream_response, query_inst.stream.return_value)
query_inst.stream.assert_called_once_with(transaction=transaction)
query_instance = query_class.return_value
self.assertIs(stream_response, query_instance.stream.return_value)
query_instance.stream.assert_called_once_with(transaction=transaction)

@mock.patch("google.cloud.firestore_v1.collection.Watch", autospec=True)
def test_on_snapshot(self, watch):
Expand Down