From 0c6702cf2eee010c68fa0280ec04400206a29567 Mon Sep 17 00:00:00 2001 From: Adam Green Date: Sat, 2 Aug 2025 17:51:26 +1000 Subject: [PATCH 1/3] Fix type signature for filter_ parameter in find methods The filter_ parameter in find() and find_one() methods now correctly supports int, float, and bool types in addition to str, matching actual Firestore usage patterns. --- firedantic/_async/model.py | 4 ++-- firedantic/_sync/helpers.py | 4 +++- firedantic/_sync/model.py | 8 +++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/firedantic/_async/model.py b/firedantic/_async/model.py index 84251df..a84b34f 100644 --- a/firedantic/_async/model.py +++ b/firedantic/_async/model.py @@ -144,7 +144,7 @@ def get_document_id(self): @classmethod async def find( # pylint: disable=too-many-arguments cls: Type[TAsyncBareModel], - filter_: Optional[Dict[str, Union[str, dict]]] = None, + filter_: Optional[Dict[str, Union[str, int, float, bool, dict]]] = None, order_by: Optional[_OrderBy] = None, limit: Optional[int] = None, offset: Optional[int] = None, @@ -224,7 +224,7 @@ def _add_filter( @classmethod async def find_one( cls: Type[TAsyncBareModel], - filter_: Optional[Dict[str, Union[str, dict]]] = None, + filter_: Optional[Dict[str, Union[str, int, float, bool, dict]]] = None, order_by: Optional[_OrderBy] = None, transaction: Optional[AsyncTransaction] = None, ) -> TAsyncBareModel: diff --git a/firedantic/_sync/helpers.py b/firedantic/_sync/helpers.py index 57dfe99..3a5f92c 100644 --- a/firedantic/_sync/helpers.py +++ b/firedantic/_sync/helpers.py @@ -1,7 +1,9 @@ from google.cloud.firestore_v1 import CollectionReference -def truncate_collection(col_ref: CollectionReference, batch_size: int = 128) -> int: +def truncate_collection( + col_ref: CollectionReference, batch_size: int = 128 +) -> int: """ Removes all documents inside a collection. diff --git a/firedantic/_sync/model.py b/firedantic/_sync/model.py index 78ec372..86427a9 100644 --- a/firedantic/_sync/model.py +++ b/firedantic/_sync/model.py @@ -144,7 +144,7 @@ def get_document_id(self): @classmethod def find( # pylint: disable=too-many-arguments cls: Type[TBareModel], - filter_: Optional[Dict[str, Union[str, dict]]] = None, + filter_: Optional[Dict[str, Union[str, int, float, bool, dict]]] = None, order_by: Optional[_OrderBy] = None, limit: Optional[int] = None, offset: Optional[int] = None, @@ -224,7 +224,7 @@ def _add_filter( @classmethod def find_one( cls: Type[TBareModel], - filter_: Optional[Dict[str, Union[str, dict]]] = None, + filter_: Optional[Dict[str, Union[str, int, float, bool, dict]]] = None, order_by: Optional[_OrderBy] = None, transaction: Optional[Transaction] = None, ) -> TBareModel: @@ -236,7 +236,9 @@ def find_one( :return: The model instance. :raise ModelNotFoundError: If the entry is not found. """ - model = cls.find(filter_, limit=1, order_by=order_by, transaction=transaction) + model = cls.find( + filter_, limit=1, order_by=order_by, transaction=transaction + ) try: return model[0] except IndexError as e: From 156cfc9f2f525bf0ba1ce377cdf6697474cc81e8 Mon Sep 17 00:00:00 2001 From: Adam Green <141785926+AdamGreenAwardMatcher@users.noreply.github.com> Date: Sun, 3 Aug 2025 08:12:05 +1000 Subject: [PATCH 2/3] Update helpers.py --- firedantic/_sync/helpers.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/firedantic/_sync/helpers.py b/firedantic/_sync/helpers.py index 3a5f92c..57dfe99 100644 --- a/firedantic/_sync/helpers.py +++ b/firedantic/_sync/helpers.py @@ -1,9 +1,7 @@ from google.cloud.firestore_v1 import CollectionReference -def truncate_collection( - col_ref: CollectionReference, batch_size: int = 128 -) -> int: +def truncate_collection(col_ref: CollectionReference, batch_size: int = 128) -> int: """ Removes all documents inside a collection. From 450ce765c3cfed95f48258e4d4efb2a6c5e8cc43 Mon Sep 17 00:00:00 2001 From: Adam Green <141785926+AdamGreenAwardMatcher@users.noreply.github.com> Date: Sun, 3 Aug 2025 08:12:46 +1000 Subject: [PATCH 3/3] Update model.py --- firedantic/_sync/model.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/firedantic/_sync/model.py b/firedantic/_sync/model.py index 86427a9..28adc1b 100644 --- a/firedantic/_sync/model.py +++ b/firedantic/_sync/model.py @@ -236,9 +236,7 @@ def find_one( :return: The model instance. :raise ModelNotFoundError: If the entry is not found. """ - model = cls.find( - filter_, limit=1, order_by=order_by, transaction=transaction - ) + model = cls.find(filter_, limit=1, order_by=order_by, transaction=transaction) try: return model[0] except IndexError as e: