Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added read_time as a parameter to various calls (synchronous/base classes) #1013

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

gkevinzheng
Copy link
Contributor

This PR adds read_time to API calls that map to various Firestore gRPC calls whose request objects contain read_time as a field.

Calls with read_time added:

Client Library Call gRPC Request in Call
AggregationQuery.get/stream RunAggregationQueryRequest
Client.get_all BatchGetDocumentsRequest
Client.collections ListCollectionIdsRequest
Collection.list_documents ListDocumentsRequest
Collection.get/stream RunQueryRequest
DocumentReference.get BatchGetDocumentsRequest
DocumentReference.collections ListCollectionIdsRequest
Query.get/stream RunQueryRequest
Query.list_partitions PartitionQueryRequest
Transaction.get_all BatchGetDocumentsRequest
Transaction.get BatchGetDocumentsRequest/ RunQueryRequest

Partially fixes #775 for synchronous/base classes, async classes will be in a separate PR.

@gkevinzheng gkevinzheng requested review from a team as code owners January 30, 2025 19:08
@product-auto-label product-auto-label bot added size: l Pull request size is large. api: firestore Issues related to the googleapis/python-firestore API. labels Jan 30, 2025
@@ -20,6 +20,7 @@
"""
from __future__ import annotations

from datetime import datetime
Copy link
Contributor

@daniel-sanche daniel-sanche Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just importing datetime as a module is probably better? This import overrides the "datetime" module name with the class name, which would get a bit weird if we have to use other datetime imports in the future. And it makes some of the type annotations a bit ambiguous

But let me know what you think

read_time (Optional[datetime]): If set, reads documents as they were at the given
time. This must be a microsecond precision timestamp within the past one hour,
or if Point-in-Time Recovery is enabled, can additionally be a whole minute
timestamp within the past 7 days.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple questions:

  • how are timezones handled? Do you expect "aware" or "naive" datetimes?
  • I just did a quick search, but it seems like datetime.datetime also has microsecond precision. Do we need to mention the precision here?

field_paths: Iterable[str] | None = None,
transaction: Transaction | None = None,
field_paths: Iterable[str] = None,
transaction: Transaction = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why remove None from these? Doesn't that cause a mypy error?

retry: retries.Retry | object | None = gapic_v1.method.DEFAULT,
timeout: float | None = None,
timeout: float = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment: isn't this a type violation?

read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
time. This must be a microsecond precision timestamp within the past one hour, or
if Point-in-Time Recovery is enabled, can additionally be a whole minute timestamp
within the past 7 days. For the most accurate results, use UTC timezone.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I'm confused by this comment. Why "most accurate results". Wouldn't the wrong timezone give wrong results? How are timezones meant to be used?
  2. Shouldn't this docstring be consistent with others? I don't see UTC note this in the previous files

# make sure we didn't skip assertions in inner function
assert inner_fn_ran is True


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be good to test a read_time that is far in the past, or in the future, to make sure the exception is raised as you expect it to be

def _collections_helper(page_size=None, retry=None, timeout=None, database=None):
@pytest.mark.parametrize("database", [None, "somedb"])
def test_documentreference_get_with_read_time(database):
_get_helper(read_time=DatetimeWithNanoseconds.now(), database=database)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use from DatetimeWithNanoseconds here instead of the regular datetime?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/python-firestore API. size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support read_time queries
3 participants