-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] EntityType: 'query_builder' and 'setMaxResults' weird behavior #31559
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
Comments
The |
The issue I faced was just concerning the LIMIT. If I While I understand the semantic you describe of "You queryied a b c, so pick what you want of a b c", this is not the behavior I am observing. It's more like "Your queryied a b c, so pick whatever you want but no more than 3." But I respect your point, this is revealed anyway by a bad usage of |
Sorry, I did not understand your description that way as your example was talking about a limit of two but a submission of three values. This looks like a bug to me then. |
Okay, yeah, sorry, I probably lacked precision in my first post. I was not aware of the I will try to find time this week to investigate. |
Thank you @Adrien-H for reporting this issue, I was able to work on a fix and opened #34900. The problem is that we try to optimize the query on submission by adding a This is an edge case where we should not try to optimize the loading since we cannot fix it on the db layer, and given that is about a "limit" clause this should not be a big deal hopefully. |
…ueries with limit (HeahDude) This PR was merged into the 3.4 branch. Discussion ---------- [DoctrineBridge] Fixed submitting invalid ids when using queries with limit | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #31559 <!-- prefix each issue number with "Fix #", if any --> | License | MIT | Doc PR | ~ <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/roadmap): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch master. --> Commits ------- 09bb1e4 [DoctrineBridge] Fixed submitting invalid ids when using queries with limit
Symfony version(s) affected: 4.2.7
Description
I'm not sure this is a bug. It might be a simple question, but surely about a behavior I consider like weird.
In some Form, in some
EntityType
with'multiple' => true
, if you interfer with thequery_builder
and callsetMaxResults(x)
on the builder, thenx
will also enter in validation flow: the form field will be invalid if the number of submitted entities is greater thanx
.How to reproduce
Let's consider this:
From this point, nothing stops the frontend from sending more than 2 entities. You could imagine Select2 field with its own AJAX request. And this will lead to the form being invalid.
One could argue this makes no sense to limit the query to 2 results then sending 3 entities. While I could agree with this, my concern is not about the logic behind the behavior, but the fact that I think it's not the role of the
query_builder
option to define parallel constraints on its way or have any influence upon form validation. It is not documented, it raises very generic error messages, in one word it is rather unpredictable.Possible Solution
If it's a bug, well it's a bug, happy for having reported it. I did not have any time to dig into the code and understand the behavior, though, so I did not come out with a fix. I could try finding some time for this if you ask. (:
If it's a wanted behavior, I won't debate the choice itself, but I think it could be better documented or at least raise a more accurate error message on the form field.
The text was updated successfully, but these errors were encountered: