Skip to content

Treat path=None as the root path in JSON commands - #4444

Merged
petyaslavova merged 2 commits into
redis:masterfrom
abhishekacharya200:json-none-path-root
Oct 16, 2026
Merged

petyaslavova merged 2 commits into
redis:masterfrom
abhishekacharya200:json-none-path-root

Conversation

@abhishekacharya200

@abhishekacharya200 abhishekacharya200 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Description of change

Several JSON methods declare path: str | None, but they build the command with str(path). Passing None therefore sends the literal path "None" instead of the root:

r.json().set("arr", "$", [1, 2, 3])
r.json().arrlen("arr", None)    # ResponseError: Path does not exist
r.json().objlen("obj", None)    # None
r.json().delete("doc", None)    # 0, nothing deleted

With this change, when path is None these methods send Path.root_path(). That is what the server uses when the path is omitted, and it is already the default value of these parameters, so None now behaves the same as not passing a path. (strlen() handles None by 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, and debug("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

  • Do tests and lints pass with this change?
  • Do the CI tests pass with this change (enable it first in your forked repo and wait for the github action build to finish)?
  • Is the new or changed code fully tested?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Is there an example added to the examples folder (if applicable)?

Note

Low Risk
Targeted bugfix in JSON command argument encoding with broad test coverage; behavior only changes when callers pass explicit None for path.

Overview
Fixes a bug where JSON client methods that accept path: str | None were building Redis commands with str(path), so an explicit path=None was sent as the literal path "None" instead of the document root.

Adds _path_arg() in commands.py to map None to Path.root_path() and wires it through array, object, type/resp, clear, delete, toggle, strappend, and debug("MEMORY", ...) call sites. Signatures and non-None paths are unchanged; strlen already omitted the path when None.

Sync and asyncio test_none_path_is_root_path exercises the affected commands with path=None.

Reviewed by Cursor Bugbot for commit 31bc021. Bugbot is set up for automated code reviews on this repo. Configure here.

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-16T06:47:40.818185Z dc77cc0 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@petyaslavova petyaslavova left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@petyaslavova petyaslavova added the maintenance Maintenance (CI, Releases, etc) label Oct 16, 2026
@petyaslavova
petyaslavova merged commit 08e2499 into redis:master Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Maintenance (CI, Releases, etc)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants