Skip to content
This repository was archived by the owner on Mar 2, 2026. It is now read-only.

Commit 409ffd2

Browse files
committed
added read_time option
1 parent 9a35dfe commit 409ffd2

3 files changed

Lines changed: 31 additions & 5 deletions

File tree

google/cloud/firestore_v1/async_pipeline.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from google.cloud.firestore_v1.base_pipeline import _BasePipeline
1919

2020
if TYPE_CHECKING: # pragma: NO COVER
21+
import datetime
2122
from google.cloud.firestore_v1.async_client import AsyncClient
2223
from google.cloud.firestore_v1.pipeline_result import PipelineResult
2324
from google.cloud.firestore_v1.async_transaction import AsyncTransaction
@@ -59,6 +60,7 @@ def __init__(self, client: AsyncClient, *stages: stages.Stage):
5960
async def execute(
6061
self,
6162
transaction: "AsyncTransaction" | None = None,
63+
read_time: datetime.datetime | None = None,
6264
) -> list[PipelineResult]:
6365
"""
6466
Executes this pipeline and returns results as a list
@@ -70,12 +72,17 @@ async def execute(
7072
If a ``transaction`` is used and it already has write operations
7173
added, this method cannot be used (i.e. read-after-write is not
7274
allowed).
75+
read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
76+
time. This must be a microsecond precision timestamp within the past one hour, or
77+
if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp
78+
within the past 7 days. For the most accurate results, use UTC timezone.
7379
"""
74-
return [result async for result in self.stream(transaction=transaction)]
80+
return [result async for result in self.stream(transaction=transaction, read_time=read_time)]
7581

7682
async def stream(
7783
self,
7884
transaction: "AsyncTransaction" | None = None,
85+
read_time: datetime.datetime | None = None,
7986
) -> AsyncIterable[PipelineResult]:
8087
"""
8188
Process this pipeline as a stream, providing results through an Iterable
@@ -87,8 +94,12 @@ async def stream(
8794
If a ``transaction`` is used and it already has write operations
8895
added, this method cannot be used (i.e. read-after-write is not
8996
allowed).
97+
read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
98+
time. This must be a microsecond precision timestamp within the past one hour, or
99+
if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp
100+
within the past 7 days. For the most accurate results, use UTC timezone.
90101
"""
91-
request = self._prep_execute_request(transaction)
102+
request = self._prep_execute_request(transaction, read_time)
92103
async for response in await self._client._firestore_api.execute_pipeline(
93104
request
94105
):

google/cloud/firestore_v1/base_pipeline.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from google.cloud.firestore_v1 import _helpers
3434

3535
if TYPE_CHECKING: # pragma: NO COVER
36+
import datetime
3637
from google.cloud.firestore_v1.client import Client
3738
from google.cloud.firestore_v1.async_client import AsyncClient
3839
from google.cloud.firestore_v1.types.firestore import ExecutePipelineResponse
@@ -99,7 +100,9 @@ def _append(self, new_stage):
99100
return self.__class__._create_with_stages(self._client, *self.stages, new_stage)
100101

101102
def _prep_execute_request(
102-
self, transaction: BaseTransaction | None
103+
self,
104+
transaction: BaseTransaction | None,
105+
read_time: datetime.datetime | None,
103106
) -> ExecutePipelineRequest:
104107
"""
105108
shared logic for creating an ExecutePipelineRequest
@@ -116,6 +119,7 @@ def _prep_execute_request(
116119
database=database_name,
117120
transaction=transaction_id,
118121
structured_pipeline=self._to_pb(),
122+
read_time=read_time,
119123
)
120124
return request
121125

google/cloud/firestore_v1/pipeline.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from google.cloud.firestore_v1.base_pipeline import _BasePipeline
1919

2020
if TYPE_CHECKING: # pragma: NO COVER
21+
import datetime
2122
from google.cloud.firestore_v1.client import Client
2223
from google.cloud.firestore_v1.pipeline_result import PipelineResult
2324
from google.cloud.firestore_v1.transaction import Transaction
@@ -56,6 +57,7 @@ def __init__(self, client: Client, *stages: stages.Stage):
5657
def execute(
5758
self,
5859
transaction: "Transaction" | None = None,
60+
read_time: datetime.datetime | None = None,
5961
) -> list[PipelineResult]:
6062
"""
6163
Executes this pipeline and returns results as a list
@@ -67,12 +69,17 @@ def execute(
6769
If a ``transaction`` is used and it already has write operations
6870
added, this method cannot be used (i.e. read-after-write is not
6971
allowed).
72+
read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
73+
time. This must be a microsecond precision timestamp within the past one hour, or
74+
if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp
75+
within the past 7 days. For the most accurate results, use UTC timezone.
7076
"""
71-
return [result for result in self.stream(transaction=transaction)]
77+
return [result for result in self.stream(transaction=transaction, read_time=read_time)]
7278

7379
def stream(
7480
self,
7581
transaction: "Transaction" | None = None,
82+
read_time: datetime.datetime | None = None,
7683
) -> Iterable[PipelineResult]:
7784
"""
7885
Process this pipeline as a stream, providing results through an Iterable
@@ -84,7 +91,11 @@ def stream(
8491
If a ``transaction`` is used and it already has write operations
8592
added, this method cannot be used (i.e. read-after-write is not
8693
allowed).
94+
read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
95+
time. This must be a microsecond precision timestamp within the past one hour, or
96+
if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp
97+
within the past 7 days. For the most accurate results, use UTC timezone.
8798
"""
88-
request = self._prep_execute_request(transaction)
99+
request = self._prep_execute_request(transaction, read_time)
89100
for response in self._client._firestore_api.execute_pipeline(request):
90101
yield from self._execute_response_helper(response)

0 commit comments

Comments
 (0)