Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpKernel] Regression when ArgumentResolver::getArguments() passes an empty array of reflectors to ArgumentMetadataFactory::createArgumentMetadata() #47461

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

Closed
wants to merge 3 commits into from

Conversation

catch56
Copy link

@catch56 catch56 commented Sep 2, 2022

Q A
Branch? 6.2
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #
License MIT
Doc PR symfony/symfony-docs#...

We're in the progress of preparing Drupal 10 for Symfony 6.2 compatibility and found a regression caused by #46001

Drupal issue is https://www.drupal.org/project/drupal/issues/3284422 (no dedicated issue for this yet)

Easiest way to see this is the original diff from that MR, i.e. https://github.com/symfony/symfony/pull/46001/files#diff-d3747dd395ddb12ee6fd6bdd911faa1cab4e10cfa69489918bf443fc2d25ba2fL28

Restoring the specific handling for $controller as array seems to be enough to fix things on our end, although maybe the call to ReflectionFunction can be changed to handle it too. Just trying to get this up quickly for discussion.

The symptom of this is that the arguments don't get passed to the controller, which is fatal errors everywhere.

@nicolas-grekas
Copy link
Member

Thanks for the patch. Can you please add a test case to prevent any regressions?

@xabbuh xabbuh added HttpKernel and removed Feature labels Sep 2, 2022
@carsonbot carsonbot changed the title Regression when $controller as array is passed to ArgumentMetadataFactory::createArgumentMetadata() [HttpKernel] Regression when $controller as array is passed to ArgumentMetadataFactory::createArgumentMetadata() Sep 2, 2022
@nicolas-grekas
Copy link
Member

nicolas-grekas commented Sep 2, 2022

The issue might be unrelated to calling ReflectionFunction vs ReflectionMethod.
In your case, I'd suspect that the $reflection parameter is set and that it might be out of sync somehow.
Does moving the new ReflectionFunction outside of if (null === $reflection) fix the issue?

@catch56
Copy link
Author

catch56 commented Sep 2, 2022

Given #46001 is only in Symfony 6.2, if it was me, I would revert that, and then add it back with a fix + test for this regression.

fwiw the call to ArgumentResolver::getArguments() that's failing is in Drupal\Core\Controller\TitleResolver::getTitle()(https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Controller%21TitleResolver.php/function/TitleResolver%3A%3AgetTitle/10.0.x)

@catch56
Copy link
Author

catch56 commented Sep 2, 2022

Took a closer look. The issue might be that Symfony/Component/HttpKernel/Controller/ArgumentResolver::getArguments() passes an empty array of reflectors instead of NULL? Have updated the PR with this change.

@nicolas-grekas
Copy link
Member

I'd be happy to have a look. Can you please let me know how I can reproduce the issue after getting a fresh clone of drupal?

@catch56
Copy link
Author

catch56 commented Sep 2, 2022

So...

  1. Checkout 10.1.x
  2. Run the installer and log in
  3. Apply the patch from https://www.drupal.org/project/drupal/issues/3284422#comment-14678151 and composer update so you're running Symfony 6.2
  4. Browse to a page relying on TitleResolver like /node/add/article
  5. You should get Too few arguments to function Drupal\node\Controller\NodeController::addPageTitle(), 0 passed and exactly 1 expected

Unfortunately can't yet find a concise Drupal core test that triggers this bug - lots of Functional tests fail, but unit tests are mocking ArgumentResolver and not triggering the bug. Doesn't mean there isn't one, but haven't found it yet

@catch56 catch56 changed the title [HttpKernel] Regression when $controller as array is passed to ArgumentMetadataFactory::createArgumentMetadata() [HttpKernel] Regression when ArgumentResolver::getArguments() passes an empty array of reflectors to ArgumentMetadataFactory::createArgumentMetadata() Sep 2, 2022
@nicolas-grekas
Copy link
Member

nicolas-grekas commented Sep 2, 2022

Thanks for the details, for giving it a try, and for the reproducer!
#47468 should fix the issue.

@catch56
Copy link
Author

catch56 commented Sep 2, 2022

Oh nice one thanks for taking a proper look!

fabpot added a commit that referenced this pull request Sep 2, 2022
… request (nicolas-grekas)

This PR was merged into the 6.2 branch.

Discussion
----------

[HttpKernel] Don't cache controller's reflector inside the request

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #47461
| License       | MIT
| Doc PR        | -

Issue introduced by #46001

Commits
-------

c751bd0 [HttpKernel] Don't cache controller's reflector inside the request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants