Fix regression in count
database helper when counting filtered related fields
#22448
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.
Scope
A special case that slipped the cracks of #22297: When counting the items of a related field, that is filtered down using permissions, we incorrectly use the un-aliased collection name for the joins in
addJoin
.You can reproduce this by setting up the following collections
videos
collectionbattles
collection with at least astatus
field and a o2m relation to thevideos
collections, calledvideos
, call the foreign keybattle
Create a test role and set the permissions:
battles
collection toAll Access
for readingvideos
collection toCustom
. Allow all fields and set the Item Permission filter to{"_and":[{"battle_id":{"status":{"_eq":"published"}}}]}
Without this PR you should see the error as described in #22443 for the GraphQL query
What's changed:
Add the newly aliased related collection to the alias map as parent collection with an empty string as key for the nested
applyFilter
. This will causeaddJoin
to use this alias asaliasedParentCollection
instead of the real name of the collection here, asparentFields
is undefined for the first level of nested filter.directus/api/src/utils/apply-query.ts
Line 165 in 1d65b0d
For additional levels of nested filters
parentFields
has the parent collections in there as thus the behavior is still the default behavior for nested filters.Potential Risks / Drawbacks
None, hopefully
Review Notes / Questions
Fixes #22443