Skip to content

Report the reducer in unified TS.MRANGE/MREVRANGE metadata on RESP2 with GROUPBY - #4634

Merged
petyaslavova merged 2 commits into
redis:masterfrom
astroknot-sheep:fix/unified-mrange-groupby-metadata-resp2
Nov 16, 2026
Merged

petyaslavova merged 2 commits into
redis:masterfrom
astroknot-sheep:fix/unified-mrange-groupby-metadata-resp2

Conversation

@astroknot-sheep

@astroknot-sheep astroknot-sheep commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Description of change

With legacy_responses=False, a grouped TS.MRANGE / TS.MREVRANGE returns different metadata on RESP2 and RESP3. RESP3 sends the metadata, {"reducers": ["sum"]}. RESP2 doesn't send any, so parse_m_range_unified builds it from the call options, but it only looks at aggregation_type, so it always returns {"aggregators": [...]}:

for protocol in (2, 3):
    r = redis.Redis(protocol=protocol, legacy_responses=False, decode_responses=True)
    res = r.ts().mrange("-", "+", ["team=ny"], groupby="team", reduce="sum")
    print(protocol, res["team=ny"][1])

# 2 {'aggregators': []}
# 3 {'reducers': ['sum']}

This passes reduce to the response callback too (only when groupby is set), like aggregation_type already is, and _m_range_metadata returns {"reducers": [reduce]} in lower case, the way the server reports it. The RESP3 path doesn't change.

Added test_mrange_groupby_unified_metadata_matches_on_both_protocols, which runs a grouped mrange and mrevrange on protocol 2 and 3 and checks both results are the same. It fails on master and passes now. tests/test_timeseries.py and tests/test_asyncio/test_timeseries.py pass locally with and without --legacy-responses=false (redis-stack-server 7.4.0); ruff is clean.

I used an AI assistant while working on this; I reproduced it, reviewed the change and ran the tests myself.

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
Narrow change to unified TimeSeries response parsing for GROUPBY queries; behavior fix with targeted tests and no API surface change beyond corrected metadata shape.

Overview
With legacy_responses=False, grouped TS.MRANGE / TS.MREVRANGE replies now expose the same metadata on RESP2 as on RESP3. RESP2 does not send metadata on the wire, so the client synthesizes it; previously it only used aggregation_type, producing {"aggregators": [...]} even when GROUPBY / REDUCE was used, while RESP3 correctly returned {"reducers": [...]}.

mrange and mrevrange now forward reduce into the response parser when groupby is set (mirroring aggregation_type). _m_range_metadata prefers reduce and emits lowercase reducers. A new integration test asserts protocol 2 and 3 match for grouped mrange and mrevrange.

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T09:21:27.297320Z e34bfaa New commits
ℹ️ 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 @astroknot-sheep, thank you for your contribution!

The fix looks good to me: passing reduce to the callback only when groupby is set matches when GROUPBY is actually sent, and the cross-protocol test covers both the plain and the aggregated GROUPBY cases. I'll approve once CI is green.

@petyaslavova
petyaslavova merged commit b970e6a into redis:master Nov 16, 2026
132 checks passed
petyaslavova added a commit that referenced this pull request Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants