Skip to content

Commit

Permalink
Update firestore to use FieldFilter.
Browse files Browse the repository at this point in the history
Fix: #431
UserWarning in build log: Detected filter using positional arguments.
Prefer using the 'filter' keyword argument instead
The filter argument takes BaseFilter class which is an abstract class
and it is implemented in FieldFilter. This class can be imported from
google.cloud.firestore_v1.base_query
Reference: googleapis/python-firestore#705
	   GoogleCloudPlatform/python-docs-samples#10407
  • Loading branch information
danghai authored and spbnick committed Dec 5, 2023
1 parent 92b925f commit c2de292
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions kcidb/monitor/spool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import email
import email.policy
from google.cloud import firestore
from google.cloud.firestore_v1.base_query import FieldFilter
from kcidb.misc import ArgumentParser, iso_timestamp, log_and_print_excepthook
from kcidb.monitor.misc import is_valid_firestore_id
from kcidb.monitor.output import Notification
Expand Down Expand Up @@ -238,8 +239,9 @@ def wipe(self, until=None):
isinstance(until, datetime.datetime) and until.tzinfo
if until is None:
until = datetime.datetime.now(datetime.timezone.utc)
field_filter = FieldFilter("created_at", "<=", until)
for snapshot in \
self._get_coll().where("created_at", "<=", until). \
self._get_coll().where(filter=field_filter). \
select([]).stream():
snapshot.reference.delete()

Expand All @@ -259,8 +261,9 @@ def unpicked(self, timestamp=None):
isinstance(timestamp, datetime.datetime) and timestamp.tzinfo
if timestamp is None:
timestamp = datetime.datetime.now(datetime.timezone.utc)
field_filter = FieldFilter("picked_until", "<", timestamp)
for snapshot in \
self._get_coll().where("picked_until", "<", timestamp). \
self._get_coll().where(filter=field_filter). \
select([]).stream():
id = snapshot.id
assert Client.is_valid_id(id)
Expand Down

0 comments on commit c2de292

Please sign in to comment.