Skip to content

Commit 424b842

Browse files
Savannah Noremslorello89
Savannah Norem
andauthored
Test the FindQuery class and how it turns expressions into Redis commands (#642)
* added return_fields function, attempting to optionally limit fields returned by find * added call to get query, adding tests * cleaned up test file, added endswith test * cleaned up one more return fields line, added fuzzy matching and cleaned up some tests * remove changes - return_fields doesn't exist here, that'll be it's own branch * removing whitespace from blank lines for linter * fixing linter issues * ignorning erroneous error * making xfix tests more specific * linting fixes * removing validate return fields function as return_fields don't exist here --------- Co-authored-by: slorello89 <[email protected]>
1 parent f245488 commit 424b842

File tree

5 files changed

+496
-14
lines changed

5 files changed

+496
-14
lines changed

aredis_om/model/encoders.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def jsonable_encoder(
9090
sqlalchemy_safe=sqlalchemy_safe,
9191
)
9292
if dataclasses.is_dataclass(obj):
93-
return dataclasses.asdict(obj)
93+
return dataclasses.asdict(obj) # type: ignore[call-overload]
9494
if isinstance(obj, Enum):
9595
return obj.value
9696
if isinstance(obj, PurePath):

aredis_om/model/model.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,9 @@ def resolve_redisearch_query(cls, expression: ExpressionOrNegated) -> str:
873873

874874
return result
875875

876-
async def execute(self, exhaust_results=True, return_raw_result=False):
876+
async def execute(
877+
self, exhaust_results=True, return_raw_result=False, return_query_args=False
878+
):
877879
args: List[Union[str, bytes]] = [
878880
"FT.SEARCH",
879881
self.model.Meta.index_name,
@@ -898,6 +900,9 @@ async def execute(self, exhaust_results=True, return_raw_result=False):
898900
if self.nocontent:
899901
args.append("NOCONTENT")
900902

903+
if return_query_args:
904+
return self.model.Meta.index_name, args
905+
901906
# Reset the cache if we're executing from offset 0.
902907
if self.offset == 0:
903908
self._model_cache.clear()
@@ -931,6 +936,10 @@ async def execute(self, exhaust_results=True, return_raw_result=False):
931936
self._model_cache += _results
932937
return self._model_cache
933938

939+
async def get_query(self):
940+
query = self.copy()
941+
return await query.execute(return_query_args=True)
942+
934943
async def first(self):
935944
query = self.copy(offset=0, limit=1, sort_fields=self.sort_fields)
936945
results = await query.execute(exhaust_results=False)

0 commit comments

Comments
 (0)