-
-
Notifications
You must be signed in to change notification settings - Fork 889
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(doctrine): Handle invalid uuid
in ORM SearchFilter
#6851
base: 3.4
Are you sure you want to change the base?
fix(doctrine): Handle invalid uuid
in ORM SearchFilter
#6851
Conversation
alexndlm
commented
Dec 6, 2024
Q | A |
---|---|
Branch? | 3.4 |
Tickets | |
License | MIT |
Doc PR |
uuid
in ORM SearchFilter
1b26f2c
to
01dd831
Compare
01dd831
to
fabee6f
Compare
Thanks for your patch but an invalid uuid parameter should never reach the filter, in 3.x there's the query_parameter_validator and since 3.4 and 4.0 you can use a |
Thanks, I got it. But why does the SearchFilter have similar behaviour for Also, all other filters have similar behaviour - ignore the filter if the value is invalid. |
I'm a bit disagree that the filtering by wrong id should envolve the filter ignoring, I think that the returning of the empty response in that case will be more correct. |
We're trying to improve filtering on API Platform and it has been really difficult not to break the SearchFilter as it is used for way too many data types. If you follow what's been done at #6775 we should just implement an |
I looked into the proposed solution with parameter validation and found that it works with strings but not with arrays, although |
@soyuka for me it looks strange a bit to have a coupling to Symfony's Asserts on resources that cannot be created or updated by api operation. |
Assertions are used for validating any kind of input, it's perfect for query parameters and already available since API platform 3.4! |
@soyuka let me clarify the issue with validating a parameter that could be a string or an array (which is exaclty the case with Let's say we have a filter The Now let's try to use QueryParameter with constraints. If we add
then the first case will work, but the second case will give an error And if we change it to support arrays
Then the 2nd case will work, but the 1st one will give an error |
What about https://symfony.com/doc/current/reference/constraints/AtLeastOneOf.html ? Also you can transform strings into Real uuids if needed with a Parameter provider. |
An example of a transformation in a parameter provider: https://github.com/api-platform/core/pull/6876/files#diff-9f7fc3d04b4b395b3d6962bac2cdf74b4349979e377cc26dedd092c3b15319d6 |
Anyway, don't you think that it brokes consistensy a bit, otherwise we need to implement such parameter validation for any property in SearchFilter? Moreover, the most projects are didn't use validation on query parameters, the most common cases when validation is used is cases when request has a body and we validating its content. |
@soyuka thank you for the idea, The Parameter provider option works too, but I'm not sure how to specify
|
There's a filter context however we're reworking filters to make this easier |
@ERuban this is a long going work, history is at #2400 and @vinceAmstoutz did a tremendous work around filters to make them easier to use with Parameters (#6775). The idea is to have more separation of concerns and having a SearchFilter on multiple types is, in my opinion, a very bad idea. It brought so many bugs in the past we need something more future-proof. Therefore, the future of the SearchFilter will be splitted into several filters such as: ExactStringFilter, PartialStringFilter, IriFilter (this one is for searching relations and takes an IRI or an
The idea is that you won't have more work to do:
And this also solves the issue we had where you could not easily change how to create your queryParameters. |