Skip to content

Commit 2ed7eb5

Browse files
committed
More conditionally adding read_time to kwargs
1 parent 4e6f95e commit 2ed7eb5

File tree

9 files changed

+64
-45
lines changed

9 files changed

+64
-45
lines changed

google/cloud/firestore_v1/base_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,9 @@ def _prep_get_all(
448448
"documents": document_paths,
449449
"mask": mask,
450450
"transaction": _helpers.get_transaction_id(transaction),
451-
"read_time": read_time,
452451
}
452+
if read_time is not None:
453+
request["read_time"] = read_time
453454
kwargs = _helpers.make_retry_timeout_kwargs(retry, timeout)
454455

455456
return request, reference_map, kwargs
@@ -477,8 +478,9 @@ def _prep_collections(
477478
"""Shared setup for async/sync :meth:`collections`."""
478479
request = {
479480
"parent": "{}/documents".format(self._database_string),
480-
"read_time": read_time,
481481
}
482+
if read_time is not None:
483+
request["read_time"] = read_time
482484
kwargs = _helpers.make_retry_timeout_kwargs(retry, timeout)
483485

484486
return request, kwargs

google/cloud/firestore_v1/base_collection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ def _prep_list_documents(
217217
# include any fields. To save on data transfer, we can set a field_path mask
218218
# to include no fields
219219
"mask": {"field_paths": None},
220-
"read_time": read_time,
221220
}
221+
if read_time is not None:
222+
request["read_time"] = read_time
222223
kwargs = _helpers.make_retry_timeout_kwargs(retry, timeout)
223224

224225
return request, kwargs

google/cloud/firestore_v1/base_document.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ def _prep_batch_get(
307307
"documents": [self._document_path],
308308
"mask": mask,
309309
"transaction": _helpers.get_transaction_id(transaction),
310-
"read_time": read_time,
311310
}
311+
if read_time is not None:
312+
request["read_time"] = read_time
312313
kwargs = _helpers.make_retry_timeout_kwargs(retry, timeout)
313314

314315
return request, kwargs
@@ -335,8 +336,9 @@ def _prep_collections(
335336
request = {
336337
"parent": self._document_path,
337338
"page_size": page_size,
338-
"read_time": read_time,
339339
}
340+
if read_time is not None:
341+
request["read_time"] = read_time
340342
kwargs = _helpers.make_retry_timeout_kwargs(retry, timeout)
341343

342344
return request, kwargs

google/cloud/firestore_v1/base_query.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,8 +1448,9 @@ def _prep_get_partitions(
14481448
"parent": parent_path,
14491449
"structured_query": query._to_protobuf(),
14501450
"partition_count": partition_count,
1451-
"read_time": read_time,
14521451
}
1452+
if read_time is not None:
1453+
request["read_time"] = read_time
14531454
kwargs = _helpers.make_retry_timeout_kwargs(retry, timeout)
14541455

14551456
return request, kwargs

tests/unit/v1/test_client.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,13 @@ def __iter__(self):
307307
assert collection.id == collection_id
308308

309309
base_path = client._database_string + "/documents"
310+
expected_request = {
311+
"parent": base_path,
312+
}
313+
if read_time is not None:
314+
expected_request["read_time"] = read_time
310315
firestore_api.list_collection_ids.assert_called_once_with(
311-
request={
312-
"parent": base_path,
313-
"read_time": read_time,
314-
},
316+
request=expected_request,
315317
metadata=client._rpc_metadata,
316318
**kwargs,
317319
)
@@ -417,15 +419,17 @@ def _get_all_helper(
417419
mask = common.DocumentMask(field_paths=field_paths)
418420

419421
kwargs.pop("transaction", None)
422+
expected_request = {
423+
"database": client._database_string,
424+
"documents": doc_paths,
425+
"mask": mask,
426+
"transaction": txn_id,
427+
}
428+
if read_time is not None:
429+
expected_request["read_time"] = read_time
420430

421431
client._firestore_api.batch_get_documents.assert_called_once_with(
422-
request={
423-
"database": client._database_string,
424-
"documents": doc_paths,
425-
"mask": mask,
426-
"transaction": txn_id,
427-
"read_time": read_time,
428-
},
432+
request=expected_request,
429433
metadata=client._rpc_metadata,
430434
**kwargs,
431435
)
@@ -490,7 +494,6 @@ def test_client_get_all_unknown_result(database):
490494
"documents": doc_paths,
491495
"mask": None,
492496
"transaction": None,
493-
"read_time": None,
494497
},
495498
metadata=client._rpc_metadata,
496499
)

tests/unit/v1/test_collection.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,18 @@ def _next_page(self):
318318
assert document.id == document_id
319319

320320
parent, _ = collection._parent_info()
321+
expected_request = {
322+
"parent": parent,
323+
"collection_id": collection.id,
324+
"page_size": page_size,
325+
"show_missing": True,
326+
"mask": {"field_paths": None},
327+
}
328+
if read_time is not None:
329+
expected_request["read_time"] = read_time
330+
321331
api_client.list_documents.assert_called_once_with(
322-
request={
323-
"parent": parent,
324-
"collection_id": collection.id,
325-
"page_size": page_size,
326-
"show_missing": True,
327-
"mask": {"field_paths": None},
328-
"read_time": read_time,
329-
},
332+
request=expected_request,
330333
metadata=client._rpc_metadata,
331334
**kwargs,
332335
)

tests/unit/v1/test_cross_language.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ def test_get_testprotos(test_proto):
154154
"documents": [doc._document_path],
155155
"mask": None,
156156
"transaction": None,
157-
"read_time": None,
158157
}
159158

160159
firestore_api.batch_get_documents.assert_called_once_with(

tests/unit/v1/test_document.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -468,14 +468,17 @@ def WhichOneof(val):
468468
else:
469469
expected_transaction_id = None
470470

471+
expected_request = {
472+
"database": client._database_string,
473+
"documents": [document_reference._document_path],
474+
"mask": mask,
475+
"transaction": expected_transaction_id,
476+
}
477+
if read_time is not None:
478+
expected_request["read_time"] = read_time
479+
471480
firestore_api.batch_get_documents.assert_called_once_with(
472-
request={
473-
"database": client._database_string,
474-
"documents": [document_reference._document_path],
475-
"mask": mask,
476-
"transaction": expected_transaction_id,
477-
"read_time": read_time,
478-
},
481+
request=expected_request,
479482
metadata=client._rpc_metadata,
480483
**kwargs,
481484
)
@@ -566,13 +569,16 @@ def __iter__(self):
566569
assert isinstance(collection, CollectionReference)
567570
assert collection.parent == document
568571
assert collection.id == collection_id
572+
573+
expected_result = {
574+
"parent": document._document_path,
575+
"page_size": page_size,
576+
}
577+
if read_time is not None:
578+
expected_result["read_time"] = read_time
569579

570580
api_client.list_collection_ids.assert_called_once_with(
571-
request={
572-
"parent": document._document_path,
573-
"page_size": page_size,
574-
"read_time": read_time,
575-
},
581+
request=expected_result,
576582
metadata=client._rpc_metadata,
577583
**kwargs,
578584
)

tests/unit/v1/test_query.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -970,13 +970,15 @@ def _collection_group_get_partitions_helper(
970970
parent,
971971
orders=(query._make_order("__name__", query.ASCENDING),),
972972
)
973+
expected_request = {
974+
"parent": parent_path,
975+
"structured_query": partition_query._to_protobuf(),
976+
"partition_count": 2,
977+
}
978+
if read_time is not None:
979+
expected_request["read_time"] = read_time
973980
firestore_api.partition_query.assert_called_once_with(
974-
request={
975-
"parent": parent_path,
976-
"structured_query": partition_query._to_protobuf(),
977-
"partition_count": 2,
978-
"read_time": read_time,
979-
},
981+
request=expected_request,
980982
metadata=client._rpc_metadata,
981983
**kwargs,
982984
)

0 commit comments

Comments
 (0)