You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The errors out of Firestore API are generally pretty clear, but given that FireO is already checking for a List when filtering on id field, does it make sense to also ensure the user passes a valid comparison, i.e. in clause?
FireO is otherwise not currently not providing operator validation, but firestore library is providing and not catching in this case. In theory the firestore library could be expanded to support more operators. It is worth noting that the current use of this __name__ sentinenal and in operator doesn't appear to be documented.
File "/Users/dhodun/developer/FireO/src/fireo/queries/query_iterator.py", line 22, in __init__
self.docs = query.query().stream(query.query_transaction)
File "/Users/dhodun/developer/FireO/src/fireo/queries/filter_query.py", line 257, in query
ref = ref.where(*f)
File "/Users/dhodun/developer/FireO/.venv/lib/python3.9/site-packages/google/cloud/firestore_v1/base_collection.py", line 268, in where
return query.where(field_path, op_string, value)
File "/Users/dhodun/developer/FireO/.venv/lib/python3.9/site-packages/google/cloud/firestore_v1/base_query.py", line 340, in where
op=_enum_from_op_string(op_string),
File "/Users/dhodun/developer/FireO/.venv/lib/python3.9/site-packages/google/cloud/firestore_v1/base_query.py", line 960, in _enum_from_op_string
raise ValueError(msg)
ValueError: Operator string 'has' is invalid. Valid choices are: !=, <, <=, ==, >, >=, array_contains, array_contains_any, in, not-in.
Leave in the type checking and add operator type checking as well
this is very special case of the filter() query and easy to mess up, since it isn't documented
The document_ref conversion here is actually pretty helpful since FireO users generally don't have to think about document refs or collection names
accept this is special case so extra validation is warranted, whereas other queries are checked by Firestore client instead of FireO
understand that if Firestore API accepts more operators on this sentinel in the future, FireO validation will need to be updated to allow them
Here is an example of the server side type checking for this error. It's not the most clear. Also, the emulator returns an empty list here and no error. You have to target Firestore itself to get the error:
classTestModel(Model):
name=TextField()
test1=TestModel(name="test1")
test1.save()
fromgoogle.cloudimportfirestore# writing in firestore Client since FireO won't allow the non-list in the querydb=firestore.Client()
print(db.collection('test_model').where("__name__", "==", test1.id).get())
File "/Users/dhodun/developer/FireO/.venv/lib/python3.9/site-packages/google/api_core/retry.py", line 190, in retry_target
return target()
File "/Users/dhodun/developer/FireO/.venv/lib/python3.9/site-packages/google/api_core/grpc_helpers.py", line 166, in error_remapped_callable
raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.InvalidArgument: 400 __key__ filter value must be a Key
The text was updated successfully, but these errors were encountered:
As far as I can tell, the only operator that will work on
__name__
/ ID field isin
:https://cloud.google.com/firestore/docs/query-data/queries#query_operators
The errors out of Firestore API are generally pretty clear, but given that FireO is already checking for a List when filtering on
id
field, does it make sense to also ensure the user passes a valid comparison, i.e.in
clause?FireO is otherwise not currently not providing operator validation, but
firestore
library is providing and not catching in this case. In theory the firestore library could be expanded to support more operators. It is worth noting that the current use of this__name__
sentinenal andin
operator doesn't appear to be documented.Example from:
To remain consistent either I would:
filter()
query and easy to mess up, since it isn't documentedFireO
validation will need to be updated to allow themHere is an example of the server side type checking for this error. It's not the most clear. Also, the emulator returns an empty list here and no error. You have to target Firestore itself to get the error:
The text was updated successfully, but these errors were encountered: