Repository navigation
Fix sort_by on embedded model field paths - #871
Open
VanditGupta wants to merge 1 commit into
Open
VanditGupta wants to merge 1 commit into
VanditGupta wants to merge 1 commit into
Conversation
Assisted-by: Claude
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #431
Summary
sort_by()rejected embedded model fields:validate_sort_fieldsonly looked at the model's top-level fields, sosort_by("metrics__score")andsort_by("metrics.score")both raisedQueryNotSupportedError("that field does not exist on the model"), even thoughfind()on the same field works.This adds a small
_resolve_sort_fieldhelper that acceptsparent__childorparent.child, walks the sameExpressionProxychainfind()uses, and returns the field plus its RediSearch name (<parent>_<child>, e.g.metrics_score). Validation uses it for the existing sortable/indexed checks, andresolve_redisearch_sort_fieldsuses it for theSORTBYname. Top-level fields and the KNN score field behave as before. A path to a field that doesn't exist, or one that is neithersortablenorindexed, still raisesQueryNotSupportedError.Added
test_sorting_on_embedded_fieldintests/test_json_model.py: ascending and descending order with both separators, the generatedSORTBYarguments, and both error cases. Only the async code and tests are edited; the sync versions are generated bymake sync.Testing
Run in a Linux Docker container with
redis/redis-stack-server, on this branch:tests/and in the generatedtests_sync/. On the unmodified code it fails with the error from the issue.tests/andtests_sync/: everything passes excepttest_cli_migrate.py(2 tests in each directory). Those fail the same way without this change, because the CLI subprocess in my setup cannot reach Redis.ruff check,ruff format --checkandmypy(themake lintcommands) pass.Not run:
make testitself (I ran pytest directly against one Redis Stack instance, without-n autoor coverage),make test_ossagainst OSS Redis, and nested paths deeper than one embedded level.AI assistance
This change was drafted with an AI coding assistant (Claude) and then reviewed by me.
Note
Low Risk
Localized query-layer change with tests; behavior for top-level sort fields and KNN is preserved.
Overview
sort_by()now accepts embedded JsonModel field paths (metrics__scoreormetrics.score), matching whatfind()already supports on nested fields.FindQuerygains_resolve_sort_field, which walks the sameExpressionProxychain as filter expressions and maps paths to RediSearch index names (e.g.metrics_score).validate_sort_fieldsandresolve_redisearch_sort_fieldsuse it for existence/sortable checks andSORTBYargs; top-level fields and KNN score sorting are unchanged. Invalid or non-sortable embedded paths still raiseQueryNotSupportedError.Adds
test_sorting_on_embedded_fieldfor asc/desc order,SORTBYresolution, and error cases.Reviewed by Cursor Bugbot for commit b2e0697. Bugbot is set up for automated code reviews on this repo. Configure here.