Skip to content

fix(query): refuse keyed values in a having alias comparison - #1097

Merged
abnegate merged 1 commit into
mainfrom
fix/having-alias-list
Dec 1, 2026
Merged

abnegate merged 1 commit into
mainfrom
fix/having-alias-list

Conversation

@abnegate

@abnegate abnegate commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

A having condition on a SUM/COUNT/AVG alias checked its value count and that each value is finite, but not that values is a list, so greaterThan(total, ['x' => 10]) passed — at the top level and inside and()/or(). It is now refused with GreaterThan query values must be a list, as the filter rules refuse it for attributes. (MIN/MAX aliases already went through Filter.)

Found in review of the Rust port (appwrite/appwrite#16355), which gets the same fix.

Test Plan

  • Two QueryShapeHavingTest cases (top level and in a logical group); both fail without the fix
  • Validator unit tests (1,095) pass; Pint and PHPStan clean

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • HAVING conditions with keyed values are now rejected when values must be provided as a list, including conditions inside OR groups.

An aggregate alias comparison skipped the list-shape check the filter rules apply, so greaterThan(total, ['x' => 10]) passed at any depth.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@appwrite

appwrite Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Code review

Commit Status Tier Verdict Details
b1a4736 Reviewed Reviewed 🟢 S · Ready to merge ✅ Approved View review

The added validation matches the existing filter contract, and both direct and nested cases are covered by tests.

The having validator now rejects keyed value arrays when comparing aggregate aliases, matching the list-shape rule used by ordinary filter queries. The query-shape tests cover both direct alias comparisons and comparisons nested in a logical group.

Walkthrough (2)
File Change
src/Database/Validator/Query/Having.php Reject non-list values before validating aggregate-alias comparisons.
tests/unit/Validator/QueryShapeHavingTest.php Add regression cases for keyed alias values at the top level and in a logical group.

Reviewed b1a4736

Tip

Comment @appwrite review to re-run, or mention @appwrite with a question.

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The HAVING validator now rejects aggregate-alias conditions with keyed query values. Tests cover direct conditions and conditions inside an Or group.

Changes: HAVING validation

Layer / File(s) Summary
Validate HAVING alias values
src/Database/Validator/Query/Having.php, tests/unit/Validator/QueryShapeHavingTest.php
isValidAliasCondition rejects query values that are not a list and sets the error GreaterThan query values must be a list. Tests cover direct HAVING conditions and conditions inside an Or group.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: appwrite

Merge Risk: Minimal · up to b1a47

HAVING comparisons on aggregate aliases now reject keyed values with a clear error. Valid list inputs are unchanged, and no merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the change: HAVING alias comparisons now refuse keyed values. The raw summary says Having::isValidAliasCondition rejects non-list values with the error 'GreaterThan query values must b…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change: HAVING alias comparisons now refuse keyed values. The raw summary says Having::isValidAliasCondition rejects non-list values with the error 'GreaterThan query values must be a list', and the added tests cover top-level and Or-group cases. The title is specific and matches the main change. The title uses the conventional 'fix(query):' prefix and is 60 characters long, within a typical limit.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 13638a7 and b1a4736.

Files selected for processing: 2

  • src/Database/Validator/Query/Having.php
  • tests/unit/Validator/QueryShapeHavingTest.php

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@abnegate
abnegate merged commit 4c8d7de into main Dec 1, 2026
31 checks passed
@abnegate
abnegate deleted the fix/having-alias-list branch December 1, 2026 03:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant