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

support commas in data_attrs query param #488

Merged
merged 8 commits into from
Dec 19, 2024

Conversation

annashamray
Copy link
Collaborator

@annashamray annashamray commented Nov 29, 2024

Fixes #472

We use comma as a separator between data_attrs values
If we want to support commas inside values we can consider several options:

  1. Remove several value groups, separated by commas, so comma won't be a reserved character here
    Before: ?data_attrs=naam__icontains__anna,naam__icontains__Advies
    After:?data_attrs=naam__icontains__anna&data_attrs=naam__icontains__Advies, support

    This is my personal favorite option, but it will break current API

  2. Change separator from comma to other character, for example to |.
    Before: ?data_attrs=naam__icontains__anna,naam__icontains__Advies
    After: ?data_attrs=naam__icontains__anna|naam__icontains__Advies, support

    Also a nice option, but also breaks current API

  3. Escape comma in the value part or use other char instead of comma in the value
    Here comma in the value is replaced with \,
    Before: ?data_attrs=naam__icontains__anna,naam__icontains__Advies
    After: ?data_attrs=naam__icontains__anna,naam__icontains__Advies\, support

    This options is implemented in the PR, since it doesn't break the API

  4. Use some regex magic to define when comma is used as separator and when it's used as a part of value.
    Let's not do it, since it's very tricky and unclear what happens

What do you think is the best way to implement it?
Should we introduce the breaking change? The next big release already contains a breaking change, since we remove v1 endpoints

@joeribekker @stevenbal @SonnyBA @Coperh let's discuss it

@annashamray annashamray force-pushed the feature/472-data-attr-contains-comma branch from c98824c to b07f433 Compare December 9, 2024 16:32
@annashamray annashamray marked this pull request as ready for review December 9, 2024 16:55
@joeribekker
Copy link
Member

But, when we discussed this, you said the ," is still seen as a comma and parsed early on?

@annashamray
Copy link
Collaborator Author

@joeribekker Yes, but then I realized that we still can treat \, as not comma. Please take a look at the implementation

@annashamray annashamray force-pushed the feature/472-data-attr-contains-comma branch from 8bfcc82 to 47bd81f Compare December 11, 2024 16:07
@annashamray annashamray marked this pull request as draft December 11, 2024 16:07
@annashamray annashamray marked this pull request as ready for review December 12, 2024 15:56
Copy link
Contributor

@stevenbal stevenbal left a comment

Choose a reason for hiding this comment

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

Minor comments, looks good overall 👍

* only one filtering expression is allowed

If you want to use several filtering expressions, just use this `data_attr` several times in the query string.
Example: `data_attr=height__exact__100&data_attr=naam__icontains__boom`
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpicky, but ideally explode: true would be specified here to indicate that it should be used like ?data_attr=...&data_attr=... (see https://swagger.io/docs/specification/v3_0/serialization/#query-parameters)

For example: https://github.com/open-formulieren/open-forms/blob/3a702080d35c0670588cc69b8e49445e6224989c/src/openforms/appointments/api/views.py#L64

Although looking at it, apparently explode: true is considered the default by OAS3, so I'm not sure if our schema is correct in that case 🤔. Might be something to investigate in another issue

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added it to the OAS and created issue to investigate all filters #498

src/objects/api/validators.py Outdated Show resolved Hide resolved
src/objects/tests/v2/test_filters.py Show resolved Hide resolved
@annashamray annashamray merged commit 160d5fd into master Dec 19, 2024
18 checks passed
@annashamray annashamray deleted the feature/472-data-attr-contains-comma branch December 19, 2024 10:51
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.

zoeken op waarden met een komma erin, geeft een foutmelding
3 participants