Repository navigation
fix(aggregate): refuse min and max of $permissions as of an array attribute - #1027
Merged
Merged
Conversation
…ribute $permissions is stored as a JSON list, but the aggregate validator built its map of unorderable attributes from the declared attributes only, so min() and max() of $permissions were accepted. MariaDB, MySQL and SQLite then compared the encoded text and answered a lexicographic extreme such as `[]`, and PostgreSQL failed in the engine on jsonb, while min() and max() of any declared array attribute are refused with a query error. The internal attributes stored as JSON (those with the json filter, which is $permissions) are now unorderable as array attributes are, under a join alias too. sum(), avg(), the deviations and the bitwise aggregates of $permissions were already refused as for any array; count() and countDistinct() keep counting it, as they count an array attribute. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 42 minutes. View limit details
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
8.3.0 staging QA found that
min()andmax()on$permissionswere accepted and returned[], a lexicographic extreme of the stored JSON text.min()andmax()on any declared array attribute are refused with a query error.The aggregate validator built its set of unorderable attributes from the declared attributes only.
$permissionsis an internal attribute stored as a JSON list, so it slipped through. MySQL, MariaDB and SQLite compared the encoded text, and PostgreSQL failed in the engine onjsonbwith a different error.The internal attributes stored as JSON (those carrying the
jsonfilter, which is$permissions) are now unorderable, the same as array attributes. This also applies under a join alias (alias.$permissions).Other aggregates are kept consistent with array attributes:
sum,avg, the deviations and variances, andbitAnd/bitOr/bitXorwere already refused for$permissions("requires a numeric attribute that is not an array"). The tests now pin this.countandcountDistinctkeep counting$permissions, as they count an array attribute.Regression tests
AggregationTests::testPermissionsAreAggregatedAsAnArrayAttribute: min/max/sum/avg ontags[]and$permissions, joinedother.$permissions, count/countDistinct of$permissionsthe query shape was accepted(min of$permissions)Query applies a function or operator the attribute type does not supportinstead of the validator's refusalException\Queryrefusal guard, as these adapters do not aggregate)Unit\Validator\QueryValidationTest::testMinAndMaxRefuseValuesWithoutAnOrder: max/min of$permissions, max of joinedit.$permissionsUnit\Validator\QueryValidationTest::testTheAggregateValidatorRefusesExtremaOfUnorderedTypes:$permissionswith arrays; count/countDistinct accepted; sum/avg/bitOr refusedRun locally against Docker: the full MySQL, MariaDB, Postgres and SQLite adapter suites pass, as do the full unit suite, Pint and PHPStan.
API repro (Appwrite)
GET /v1/tablesdb/{db}/tables/{t}/rows?queries[]=withmax("$permissions")(ormin) →400 general_query_invalid, messageInvalid query: Aggregate max requires an attribute whose values are ordered, not an array, object, boolean, spatial or vector one: $permissions. Before this PR it returned200with[].count("$permissions")→200with the row count.🤖 Generated with Claude Code