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: ViewerController #379

Merged
merged 10 commits into from Dec 20, 2023
Merged

Conversation

OskarStark
Copy link
Contributor

@OskarStark OskarStark commented Dec 4, 2023

After upgrading to Symfony 6.4, the ViewerController stopped working while throwing the following exception:

Uncaught PHP Exception LogicException: "You cannot use the "render" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle"." at AbstractController.php line 435

Upon investigation with @mvhirsch, we discovered that the service_container injected into the controller lacked the twig service. However, this shouldn't have been a problem since twig was injected directly via arguments. The root cause turned out to be the use of AbstractController::render() method, which attempts to access twig from the service container, instead of the intended ViewerController::renderView().

Additionally, I've realized that there is no necessity to inject the service_container or extend the AbstractController. We’re currently running tests to see if this resolves the issue.

Thank you for your assistance and insights

@OskarStark
Copy link
Contributor Author

Can you please approve the workflow run? Thanks

@DamienHarper
Copy link
Owner

@OskarStark Thanks for the PR.

@OskarStark
Copy link
Contributor Author

Any clue why the tests are failing?

@mvhirsch
Copy link
Contributor

mvhirsch commented Dec 6, 2023

@OskarStark pipeline is merging this branch against 5.x (not master). Maybe we overlooked something on first try?

@OskarStark
Copy link
Contributor Author

@OskarStark pipeline is merging this branch against 5.x (not master). Maybe we overlooked something on first try?

This is correct, I target 5.x as version 6 is not yet released 🤷‍♂️

@OskarStark
Copy link
Contributor Author

@DamienHarper can you please approve the workflow again? I extends the AbstractController again, lets see if that helps, thanks

@OskarStark
Copy link
Contributor Author

I don't know why

auditor-bundle 5.x CI / Tests PHP 8.1, Symfony 6.* (pull_request)

is failing 🤷‍♂️

@svenpet90
Copy link

Any update on this PR? Im eagerly waiting for this to be merged and released since we have customer projects using this bundle 😇

@OskarStark
Copy link
Contributor Author

I really don't know why this test is failing

@gassan
Copy link

gassan commented Dec 13, 2023

I really don't know why this test is failing

Probably you are still extending from SF AbstractController and therefore renderView return type does not match

Fatal error: Declaration of DH\AuditorBundle\Controller\ViewerController::renderView(string $view, array $parameters = []): Symfony\Component\HttpFoundation\Response must be compatible with Symfony\Bundle\FrameworkBundle\Controller\AbstractController::renderView(string $view, array $parameters = []): string in /opt/www/github/auditor-bundle/src/Controller/ViewerController.php on line 109

@mvhirsch
Copy link
Contributor

In Github Actions log I see this:

[critical] Uncaught PHP Exception LogicException: "You cannot use the "render" method if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle"." at AbstractController.php line 435

+1 for removing extends AbstractController. Do we really need it after this change? 😇

@OskarStark
Copy link
Contributor Author

I tried in a previous commit but was still not working.

Will try to remove it tomorrow again

@OskarStark
Copy link
Contributor Author

+1 for removing extends AbstractController. Do we really need it after this change? 😇

Removed again, lets see ...

@DamienHarper is it really needed, to reapprove the workflow run all the time?

@Riches Riches mentioned this pull request Dec 20, 2023
@OskarStark
Copy link
Contributor Author

Tests are still failing @DamienHarper, any idea?

@OskarStark
Copy link
Contributor Author

It looks like this is causing the issue:

    public function showTransactionAction(Reader $reader, string $hash): Response
    {
        $audits = $reader->getAuditsByTransactionHash($hash);

@DamienHarper
Copy link
Owner

@OskarStark When looking at the GA CI logs, it looks like it checkout hash 7ce0d368c9bec4c9b2669f6e68f062c079a9b832 which does not include latest commits 🤔

@OskarStark
Copy link
Contributor Author

OskarStark commented Dec 20, 2023

Can you approve again, it should checkout the PR code itself and not the target ref IMHO

Copy link

codecov bot commented Dec 20, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (7ce0d36) 93.14% compared to head (6f83864) 93.14%.

Additional details and impacted files
@@           Coverage Diff           @@
##              5.x     #379   +/-   ##
=======================================
  Coverage   93.14%   93.14%           
=======================================
  Files          15       15           
  Lines         350      350           
=======================================
  Hits          326      326           
  Misses         24       24           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DamienHarper
Copy link
Owner

@OskarStark hurray! you made it ;)

@DamienHarper DamienHarper merged commit a03c399 into DamienHarper:5.x Dec 20, 2023
12 checks passed
DamienHarper added a commit that referenced this pull request Dec 20, 2023
* Fix: `ViewerController`

* -

* -

* -

* Fixed remaining calls to AbstractController methods.

* -

* -

* -

* -

* PHP-CS-Fixer

---------

Co-authored-by: Damien Harper <damien.harper@gmail.com>
@OskarStark OskarStark deleted the fix/viewer-controller branch December 20, 2023 23:53
@OskarStark
Copy link
Contributor Author

Nice, can you tag a release?

@DamienHarper
Copy link
Owner

Done! (5.2.5)

@mvhirsch
Copy link
Contributor

Thank you @OskarStark and @DamienHarper !

While I love this implementation (decoupling the controller from the framework), the only downside I can image is: the ViewerController is not marked as final and just changed. This should be marked as breaking change and thus not be released as patch-version, but a major one. At least, please add it to the release notes or upgrade guideline :-)

@DamienHarper
Copy link
Owner

@mvhirsch you're welcome ;)
You're right, I should have released it as a major version bump. It's a bit late now so I updated release notes. Sorry for the inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants