Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filter validation for field functions #22060

Merged
merged 5 commits into from Apr 24, 2024
Merged

Fix filter validation for field functions #22060

merged 5 commits into from Apr 24, 2024

Conversation

paescuj
Copy link
Member

@paescuj paescuj commented Apr 3, 2024

Scope

TIL the JSON count filter is broken since v9.14.4 (🤯):

This roots back to the filter validation not accounting for field functions (count(json_field)). Fortunately, this was not an issue for functions on relations (count(...)) or dates (year(...)), since the allowed operators for the fields itself and corresponding functions overlap there.

The filter validation has now been adjusted to properly check for:

  • allowed functions on a field (e.g. count on JSON field)
  • allowed filter type / operators (e.g. integer / _eq for count function) when using functions

Still works for relations and dates:

Screenshot 2024-04-03 at 09 58 28
Screenshot 2024-04-03 at 10 06 19

Potential Risks / Drawbacks

None, only bug fixing

Review Notes / Questions

Can be tested via Data Studio or API:

  • REST:
     ?filter[count(json_field)][_eq]=1
  • GraphQL:
    query {
      test(filter: { json_field_func: { count: { _eq: 1 } } }) {
        id
        json_field_func {
          count
        }
      }
    }

Copy link

changeset-bot bot commented Apr 3, 2024

🦋 Changeset detected

Latest commit: 9f94c06

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@directus/api Patch
directus Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@paescuj paescuj requested review from a team, rijkvanzanten and DanielBiegler and removed request for a team April 3, 2024 08:43
Copy link
Contributor

@hanneskuettner hanneskuettner left a comment

Choose a reason for hiding this comment

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

Very clean changes!

api/src/utils/parse-filter-key.ts Outdated Show resolved Hide resolved
paescuj and others added 2 commits April 24, 2024 17:56
Also using this opportunity to explain the regex in comment

Co-authored-by: Hannes Küttner <[email protected]>
@paescuj paescuj enabled auto-merge (squash) April 24, 2024 16:08
@paescuj paescuj merged commit 4fe4c6e into main Apr 24, 2024
4 checks passed
@paescuj paescuj deleted the fix-function-filters branch April 24, 2024 16:10
@github-actions github-actions bot added this to the Next Release milestone Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants