fix filter breaking instead of defaulting to _eq
#10194
Merged
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.
Fixes #10056
Reported bug
?filter[value]=5
used to work, but now it'll throw error 500 and it'll only work if we do?filter[value][_eq]=5
.Investigation
At first it seemed like the "default to
_eq
" was removed, but it is actually still there:https://github.com/directus/directus/blob/main/api/src/utils/apply-query.ts#L643-L645
Turns out it was an unintended side effect from the
applyFilter
refactoring in #9804, which aligns with the reports of it not working since9.1.x
.Based on the old logic, when the value is not "objectLike", it'll be returned directly as is:
directus/packages/shared/src/utils/deep-map.ts
Lines 14 to 30 in 65291b9
Solution
Added an if statement to return value without any modifcation when it's not an object. This prevents it from being "processed" by the Object.entries like
Object.entries(5).reduce(()=> /* logic */, {})
which ended up returning{}
instead.Test