Skip to content

fix(geo): encode GEOSEARCH zeros instead of dropping them - #4356

Merged
petyaslavova merged 3 commits into
redis:masterfrom
00200200:fix-geosearch-zero-numeric-args
Oct 10, 2026
Merged

petyaslavova merged 3 commits into
redis:masterfrom
00200200:fix-geosearch-zero-numeric-args

Conversation

@00200200

@00200200 00200200 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Description of change

_geosearchgeneric guarded member, radius, width/height, and count with truthiness tests. Zero arguments must be forwarded rather than silently treated as "argument omitted", so Redis can apply its own validation:

  • geosearch(..., longitude=0, latitude=0, radius=0) sent FROMLONLAT 0 0 with no BYRADIUS
  • geosearch(..., member=0, radius=10) omitted FROMMEMBER entirely
  • geosearch(..., member="x", longitude=0, latitude=0, radius=10) sent both FROMMEMBER and FROMLONLAT instead of raising DataError
  • width=0 dropped BYBOX; count=0 dropped COUNT

GEORADIUS already uses count is not None. This uses the same is not None checks for GEOSEARCH/GEOSEARCHSTORE.

count=0 is now forwarded to Redis, which rejects it with COUNT must be > 0; previously it was silently ignored.

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)?

Tests:

  • tests/test_commands.py::TestRedisCommands::test_geosearch_forwards_zero_numeric_arguments (mock, no server)
  • tests/test_asyncio/test_commands.py::TestRedisCommands::test_geosearch_forwards_zero_numeric_arguments (async mirror)
  • extra origin-conflict case in test_geosearch_negative

GeoCommands is shared with AsyncGeoCommands, so the encoding change covers both stacks.


Note

Medium Risk
Changes command-building for GEOSEARCH/GEOSEARCHSTORE (including count=0 now reaching the server); behavior shifts for callers that relied on zeros being silently dropped.

Overview
Fixes GEOSEARCH/GEOSEARCHSTORE argument encoding so numeric 0 values are sent to Redis instead of being treated as omitted.

_geosearchgeneric now uses explicit is not None checks (aligned with GEORADIUS-style handling) for member, longitude/latitude, radius, width/height, and count. That restores correct wire commands for cases like radius=0, member=0, width=0, and count=0, and fixes mutual-exclusion validation so member plus longitude=0/latitude=0 raises DataError instead of emitting both FROMMEMBER and FROMLONLAT.

Tests add mock-based coverage that asserted command args on the wire (sync, async, and geosearchstore), plus a negative case for the origin conflict at (0, 0).

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

Truthiness checks in _geosearchgeneric omitted FROMMEMBER/BYRADIUS/BYBOX/COUNT
when the value was 0, and allowed FROMMEMBER plus FROMLONLAT at the origin.

@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 @00200200, thank you for your contribution!

The change looks good - the truthiness check really drops zeroes and need to be changed.

One thing to fix before merge: assert "COUNT" not in wire_args(...) in both new tests can never fail, because the command pieces contain b"COUNT" (bytes). Please compare against b"COUNT" so the count=None case is actually guarded.

Also, please mention in the PR description that count=0 is now forwarded and the server rejects it with COUNT must be > 0, where before it was silently ignored. That is the correct behavior, but users will notice it.

@petyaslavova petyaslavova added maintenance Maintenance (CI, Releases, etc) waiting-for-response labels Oct 2, 2026
Guard count=None in both sync and async tests, and clarify that zero arguments are forwarded for server validation.
@00200200

00200200 commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Addressed both requested changes in 7badeda: the sync and async omission assertions now compare against b"COUNT", and the PR description explicitly explains that count=0 is forwarded for Redis to reject with COUNT must be > 0. Both targeted tests pass; Ruff lint and formatting checks pass.

@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.

Thanks for the quick update - both points are addressed. The b"COUNT" assertions now actually guard the count=None case, and the description makes the count=0 behavior change clear.

LGTM, I will approve once CI passes.

@petyaslavova
petyaslavova merged commit 5294559 into redis:master Oct 10, 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