Repository navigation
Treat path=None as the root path in JSON commands - #4444
Conversation
Several JSON methods annotate path as "str | None", but they built the command with str(path), so passing None sent the literal path "None". Depending on the command this raised "Path does not exist" or silently returned None/0 (for example json().delete(key, None) deleted nothing). Send the root path when path is None, which is what the server uses when the path argument is omitted and what these methods already default to.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
petyaslavova
left a comment
There was a problem hiding this comment.
Hey @abhishekacharya200, thank you for your contribution!
The fix looks good: these methods already advertise str | None, and mapping None to the root path matches their default, so None now behaves the same as omitting the path. Keeping the explicit root path instead of omitting the argument is the right call, since arrpop with an index and the value-carrying commands need the positional path. I'll approve the CI run and merge once it's green.
Description of change
Several JSON methods declare
path: str | None, but they build the command withstr(path). PassingNonetherefore sends the literal path"None"instead of the root:With this change, when
pathisNonethese methods sendPath.root_path(). That is what the server uses when the path is omitted, and it is already the default value of these parameters, soNonenow behaves the same as not passing a path. (strlen()handlesNoneby leaving the path argument out instead. I'm happy to switch to that style if you prefer.)Affected methods:
arrappend,arrlen,arrpop,type,resp,objkeys,objlen,clear,delete/forget,toggle,strappend, anddebug("MEMORY", ...). Behavior is unchanged when a path is given. Type hints and signatures are unchanged.I added sync and asyncio tests that call each method with
path=None. They fail on master and pass with this change. I ran them against Redis 8.10.2 with the default protocol,--protocol=2,--protocol=3, and--legacy-responses=false.Pull Request check-list
Note
Low Risk
Targeted bugfix in JSON command argument encoding with broad test coverage; behavior only changes when callers pass explicit
Nonefor path.Overview
Fixes a bug where JSON client methods that accept
path: str | Nonewere building Redis commands withstr(path), so an explicitpath=Nonewas sent as the literal path"None"instead of the document root.Adds
_path_arg()incommands.pyto mapNonetoPath.root_path()and wires it through array, object, type/resp, clear, delete, toggle, strappend, anddebug("MEMORY", ...)call sites. Signatures and non-Nonepaths are unchanged;strlenalready omitted the path whenNone.Sync and asyncio
test_none_path_is_root_pathexercises the affected commands withpath=None.Reviewed by Cursor Bugbot for commit 31bc021. Bugbot is set up for automated code reviews on this repo. Configure here.