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

Optional ReferenceField's are not queryable / filterable by None #116

Closed evamaxfield closed 3 years ago

evamaxfield commented 3 years ago

Currently cannot filter on optional ReferenceFields.

Minimal reproducible example:

from fireo import fields 
from fireo.models import Model 

class TestA(Model): 
    name = fields.TextField(required=True)

class TestB(Model): 
    name = fields.TextField(required=True)
    a_ref = fields.ReferenceField(model_ref=TestA)

a = TestA()
a.name = "jack"
a.save()

b = TestB()
b.name = "jill"
b.save()

query = TestB.collection.filter("a_ref", "==", None)
print(list(query.fetch())

Raises error:

Traceback (most recent call last):
  File "/home/maxfield/active/cdp/FireO/test.py", line 20, in <module>
    print(list(query.fetch()))
  File "/home/maxfield/active/cdp/FireO/src/fireo/queries/filter_query.py", line 382, in fetch
    return QueryIterator(self)
  File "/home/maxfield/active/cdp/FireO/src/fireo/queries/query_iterator.py", line 22, in __init__
    self.docs = query.query().stream(query.query_transaction)
  File "/home/maxfield/active/cdp/FireO/src/fireo/queries/filter_query.py", line 224, in query
    for f in self.parse_where():
  File "/home/maxfield/active/cdp/FireO/src/fireo/queries/filter_query.py", line 175, in parse_where
    val = db.conn.document(val)
  File "/home/maxfield/miniconda3/envs/fireo/lib/python3.9/site-packages/google/cloud/firestore_v1/client.py", line 311, in document
    path = document_path[0].split(_helpers.DOCUMENT_PATH_DELIMITER)
AttributeError: 'NoneType' object has no attribute 'split'

I already have a fix in place so will PR in just wanted to document.

Thanks again for all the work you have already put into the library!

evamaxfield commented 3 years ago

This is entirely related to #115. I have a fix / feature PR for both.

AxeemHaider commented 3 years ago

You can change the behaviour of saving None fields Before creating PR please checkout out Ignore None Field Options might it solve your problem

evamaxfield commented 3 years ago

Thanks for the link to the docs. Didn't see those at all. Still had an issue with filtering but should be good to go with my PR.

evamaxfield commented 3 years ago

Hey @AxeemHaider any idea when a new version will be pushed with this fix?

AxeemHaider commented 3 years ago

Here is the latest version of FireO