Skip to content

Commit

Permalink
Test the FindQuery class and how it turns expressions into Redis comm…
Browse files Browse the repository at this point in the history
…ands (#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 <steve.lorello@redis.com>
  • Loading branch information
sav-norem and slorello89 authored Aug 5, 2024
1 parent f245488 commit 424b842
Show file tree
Hide file tree
Showing 5 changed files with 496 additions and 14 deletions.
2 changes: 1 addition & 1 deletion aredis_om/model/encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def jsonable_encoder(
sqlalchemy_safe=sqlalchemy_safe,
)
if dataclasses.is_dataclass(obj):
return dataclasses.asdict(obj)
return dataclasses.asdict(obj) # type: ignore[call-overload]
if isinstance(obj, Enum):
return obj.value
if isinstance(obj, PurePath):
Expand Down
11 changes: 10 additions & 1 deletion aredis_om/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,9 @@ def resolve_redisearch_query(cls, expression: ExpressionOrNegated) -> str:

return result

async def execute(self, exhaust_results=True, return_raw_result=False):
async def execute(
self, exhaust_results=True, return_raw_result=False, return_query_args=False
):
args: List[Union[str, bytes]] = [
"FT.SEARCH",
self.model.Meta.index_name,
Expand All @@ -898,6 +900,9 @@ async def execute(self, exhaust_results=True, return_raw_result=False):
if self.nocontent:
args.append("NOCONTENT")

if return_query_args:
return self.model.Meta.index_name, args

# Reset the cache if we're executing from offset 0.
if self.offset == 0:
self._model_cache.clear()
Expand Down Expand Up @@ -931,6 +936,10 @@ async def execute(self, exhaust_results=True, return_raw_result=False):
self._model_cache += _results
return self._model_cache

async def get_query(self):
query = self.copy()
return await query.execute(return_query_args=True)

async def first(self):
query = self.copy(offset=0, limit=1, sort_fields=self.sort_fields)
results = await query.execute(exhaust_results=False)
Expand Down
Loading

0 comments on commit 424b842

Please sign in to comment.