jsonapi icon indicating copy to clipboard operation
jsonapi copied to clipboard

Add support for comma-separated filter values

Open CostantiniMatteo opened this issue 5 years ago • 14 comments

Implements #235

CostantiniMatteo avatar Sep 04 '20 14:09 CostantiniMatteo

LGTM. I need to wrap my head around how to release this. I think it's a breaking change despite being what is pretty obviously a bug in the initial implementation. I'd be curious to hear what other maintainers think.

cc @jeregrine @doomspork

jherdman avatar Sep 04 '20 18:09 jherdman

I've re-read the documentation and I've made a mistake. The part I quoted in the issue is from the recommendations page so it's not supposed to be the default jsonapi behaviour.

Maybe this could be a configurable behaviour?

CostantiniMatteo avatar Sep 07 '20 13:09 CostantiniMatteo

I'm pretty certain this is the kind of behaviour users of this library would expect. My inclination is to merge this as a bug fix and call it out in the changelog.

jherdman avatar Sep 07 '20 23:09 jherdman

I do agree with you, I would expect this behaviour, however this is not jsonapi standard.

I was discussing this with @lucacorti, which pointed out that this is only a recommendation's example, and one may want to support a different a strategy for filtering, or may want to use a comma in the filter value.

Isn't it better to at least offer a way to prevent this behaviour via configuration?

CostantiniMatteo avatar Sep 08 '20 08:09 CostantiniMatteo

You've convinced me: configuration is probably the way to go here.

On Tue, Sep 8, 2020 at 4:31 AM Matteo Costantini [email protected] wrote:

I do agree with you, I would expect this behaviour, however this is not jsonapi standard.

I was discussing this with @lucacorti https://github.com/lucacorti, which pointed out that this is only a recommendation's example, and one may want to support a different a strategy for filtering, or may want to use a comma in the filter value.

Isn't it better to at least offer a way to prevent this behaviour via configuration?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jeregrine/jsonapi/pull/236#issuecomment-688710633, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAAZZCVBUFR4MFGDBAZYLLSEXTVDANCNFSM4QYOPF4Q .

jherdman avatar Sep 11 '20 17:09 jherdman

Hey @jherdman, sorry I was off the grid.

I've updated the PR to make the parsing configurable.

I don't particularly like the config name, and how I handled the tests (without sacrificing concurrency). Since they run asynchronously, tests at line 70 and 77 may change the same configuration and one of the two may fail. The problem may still arise with the current implementation, although much less likely.

Let me know what you think!

CostantiniMatteo avatar Oct 12 '20 13:10 CostantiniMatteo

Hey @jherdman, sorry I was off the grid.

Never sweat about this. F/OSS is done on a volunteer basis for the vast majority of people. Any and all contributions are much appreciated!

jherdman avatar Oct 13 '20 14:10 jherdman

Could we take the chance to also merge this one among #245 and make a new release? We ended up not using this feature so I forgot about it, but it would still be useful. What do you think?

CostantiniMatteo avatar Apr 23 '21 15:04 CostantiniMatteo

@CostantiniMatteo I think merging this would be a mistake as this is really constraining what the spec allows in term of filtering: https://jsonapi.org/format/#fetching-filtering

The spec specifies that the filter parameter is used for filtering and its content are entirely up to implementation specific strategy. Processing the filter query param with some predefined logic is really limiting in terms of what can be implemented. Maybe we could explore some delegation to a behaviour like what I implemented earlier for pagination, or leave it entirely to the library user to parse its content?

lucacorti avatar May 28 '21 20:05 lucacorti

The processing is optional and needs to be configured so it's not limiting and does not break the existing behaviour.

Maybe it can be refactored to accept a module used to parse the filter content, and include a parser with support for comma-separated values, instead of the current hard-coded solution.

CostantiniMatteo avatar Jun 04 '21 14:06 CostantiniMatteo

You can't implement all possible user needs on this, so extensible is arguably better than any built in logic.

lucacorti avatar Jun 08 '21 17:06 lucacorti

@jeregrine / @jherdman / @lucacorti / @CostantiniMatteo where do we stand with this PR? It looks like it was approved but there's been some discussion about whether this is the change we want.

doomspork avatar Jun 14 '21 23:06 doomspork

@doomspork @CostantiniMatteo as I said I think this would be better addressed with an extensible approach instead of configurable baked in logic.

lucacorti avatar Jun 15 '21 17:06 lucacorti