Firestore started showing
UserWarning: Detected filter using positional arguments. Prefer using the 'filter' keyword argument instead.
when using query.where(field_path, op_string, value)
while it's the the method from the official docs https://cloud.google.com/firestore/docs/query-data/queries
So how shall we use the 'filter' kwarg? Couldn't find docs or samples on that.
UPDATE: there is an open issue on this on GitHub https://github.com/googleapis/python-firestore/issues/705 (with no reaction from Google folks)
UPDATE2: so, basically, it should look like this
from google.cloud.firestore import CollectionReference
from google.cloud.firestore_v1.base_query import FieldFilter, BaseCompositeFilter
...
conditions = [[field, operator, value], [field, operator, value], ...]
query = CollectionReference(path1, path2, path3, ...)
query = query.where(filter=BaseCompositeFilter('AND', [FieldFilter(*_c) for _c in conditions]))
For a FieldFilter operator usual ==, !=, etc. work as specified here https://firebase.google.com/docs/firestore/query-data/queries#query_operators
Instead of 'AND' you could also use 'OPERATOR_UNSPECIFIED', but I'm not sure if it does what I think it should https://firebase.google.com/docs/firestore/reference/rest/v1/StructuredQuery#Operator
Based on @Robert G
's excellent answer you can get rid of this warning with a semi-small tweak.
Instead of:
query = collection_ref
query = query.where(field, op, value)
Do this:
from google.cloud.firestore_v1.base_query import FieldFilter
query = collection_ref
query = query.where(filter=FieldFilter(field, op, value))
And then the warning disappears. Hope this helps!
As previously posted in the comments, there's an ongoing issue currently posted in Github. For those who experience similar issues, they could check this Github link for updates regarding the issue.
In addition, you could also file for a bug so that Google Devs/Engineers could also check on this and provide immediate solutions/fixes.
You could file a bug through these links:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With