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 issue 6904 by removing the subclass parameter from model auto complete #7851

Merged

Conversation

mpoiriert
Copy link
Contributor

Subject

I am targeting this branch, because the bug was introduce here.

Closes #6904.

Changelog

### Fixed
Model Auto Complete failing in create flow of admin with subclasses

@mpoiriert mpoiriert force-pushed the issue-6904-model-auto-complete branch 2 times, most recently from b1a4467 to b0955d4 Compare June 22, 2022 23:16
@mpoiriert
Copy link
Contributor Author

@VincentLanglet Ready to review. The automation test are just checking that a subclass value is not there,. I don't think I can do more than this.

@VincentLanglet
Copy link
Member

VincentLanglet commented Jun 23, 2022

The automation test are just checking that a subclass value is not there,. I don't think I can do more than this.

Best would be a functional test to reproduce the issue from #6904. Do you think it would be possible ?

@mpoiriert
Copy link
Contributor Author

mpoiriert commented Jun 23, 2022 via email

@VincentLanglet
Copy link
Member

The fix I made for the other issue was to remove/put back the parameter in the controller but that was a "hack" since we had too many place to check. The best solution would have been to remove the parameter completely which the only wau to test would have been to check that the parameter is not there.

Does the other fix still needed then ?

@VincentLanglet VincentLanglet requested review from a team and jordisala1991 June 23, 2022 08:49
@mpoiriert
Copy link
Contributor Author

Yes since it's not the same endpoint.

Once we found all the subclass parameter that have issues we could revisit how the fix was done.

The current one seems to be a "final" fix for that specific use case.

VincentLanglet
VincentLanglet previously approved these changes Jun 23, 2022
@VincentLanglet VincentLanglet requested a review from a team June 23, 2022 11:46
Comment on lines 37 to 39
$subclass = uniqid('subclass');
$client = static::createClient();
$crawler = $client->request(Request::METHOD_GET, '/admin/tests/app/foo/create');
$crawler = $client->request(Request::METHOD_GET, '/admin/tests/app/foo/create?subclass='.$subclass);
Copy link
Member

Choose a reason for hiding this comment

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

IMHO this should go in a new test instead of modifying this one

Copy link
Member

Choose a reason for hiding this comment

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

Indeed @mpoiriert, two tests are better than one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

VincentLanglet
VincentLanglet previously approved these changes Jun 25, 2022
@jordisala1991 jordisala1991 merged commit c362499 into sonata-project:4.x Jun 25, 2022
@jordisala1991
Copy link
Member

Thanks @mpoiriert

@Geekimo
Copy link
Contributor

Geekimo commented Jul 11, 2022

Hello,
following this PR, we have issues when editing subjects that are "abstract" and use a discriminator map.
I've found a workaround by passing the subclass parameter as req_params in ModelAutocompleteType::class.
Shall we found another way to fix @mpoiriert issue that is less "global" ?

@mpoiriert
Copy link
Contributor Author

@Geekimo The issue is the way the subclass have been implemented.
What is your specific use case ? Because I removed the sublcass use from the query parameter which is conflicting. If you do an Edit the query parameter subclass is not set since it's just when you do a create.

@Geekimo
Copy link
Contributor

Geekimo commented Jul 11, 2022

@mpoiriert Our admin class can edit two entities inheriting from the same abstract entity. We found out by going back to the latest version before your fix that the subclass query parameter was missing in the ajax request, and I had to set it by hand.

@mpoiriert
Copy link
Contributor Author

@Geekimo To make sure I understand you were already making a "hook" since the behaviour wasn't suppose to accomplish what you were trying to do ?

@Geekimo
Copy link
Contributor

Geekimo commented Jul 11, 2022

@mpoiriert AFAIK there wasn't any hook.
Maybe it has never worked for edit and nobody noticed it . Strange.
Thanks for the reply.

@jordisala1991
Copy link
Member

Not sure if I follow correctly the conversation. Something broke after this PR?

@mpoiriert
Copy link
Contributor Author

mpoiriert commented Oct 11, 2022 via email

@ENDaZONELT
Copy link

@mpoiriert any news regarding this bug ? I have the same issue. Abstract entity and discriminator map. I need to pass subclass parameter manually via req_params:
'req_params' => ['subclass' => array_search(get_class($this->getSubject()), $this->getSubClasses())],

@mpoiriert
Copy link
Contributor Author

@ENDaZONELT The issue was that subclass should not be passed automatically. I don't know your exact use case but the one that I fix was because AdminA (wiht subclass) -> Calling AutoComplete of AdminB was not working because the subclass of admin A was pass to AdminB.

@mpoiriert mpoiriert deleted the issue-6904-model-auto-complete branch December 31, 2023 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
6 participants