octabytes / FireO

Google Cloud Firestore modern and simplest convenient ORM package in Python. FireO is specifically designed for the Google's Firestore
https://fireo.octabyte.io
Apache License 2.0
250 stars 29 forks source link

Cursor bug when using multiple order #104

Open harrisonzhao opened 3 years ago

harrisonzhao commented 3 years ago

I encountered a bug where using multiple "order" fields seems to error when using cursor. The cursor logic seems to join the order fields as 1 string and expect that to be a field of the model.

usage

docs = MyModel.collection.filter("order_field1", "<=", value1).order(order_field1).order(-order_field2).fetch(10)
MyModel.collection.cursor(docs.cursor).fetch(10)

stacktrace

*MyModel.collection.cursor(docs.cursor).fetch(

  File "/layers/google.python.pip/pip/lib/python3.8/site-packages/fireo/managers/managers.py", line 286, in cursor
    query.order(cursor_dict['order'])
  File "/layers/google.python.pip/pip/lib/python3.8/site-packages/fireo/queries/filter_query.py", line 365, in order
    f_name = self.model._meta.get_field(name).db_column_name
  File "/layers/google.python.pip/pip/lib/python3.8/site-packages/fireo/models/model_meta.py", line 219, in get_field
    raise FieldNotFound(f'Field "{name}" not found in model "{cls.__name__}"')
fireo.fields.errors.FieldNotFound: Field "order_field1,-order_field2" not found in model "MyModel""