Conversation
Since shopware/shopware#19304 (Shopware 6.7.14.0), the twig service is tagged with kernel.reset and ServicesResetter calls reset() on it. TwigDecorator extended the plain Twig\Environment, which has no reset() method, so messenger workers crashed with an UndefinedMethodError after handling a message. Extending Shopware\Core\Framework\Adapter\Twig\TwigEnvironment (the class Shopware itself assigns to the twig service) restores the inherited reset() on 6.7.14+ and stays compatible with 6.6 and older 6.7 releases, where TwigEnvironment already exists but the kernel.reset tag is not registered. Fixes #85 Co-authored-by: Soner <github@shyim.de>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Shopware >= 6.7.14.0 (any version containing shopware/shopware#19304), async messenger workers crash after handling a message:
Shopware PR shopware/shopware#19304 moved the Twig escape-cache clearing onto
Shopware\Core\Framework\Adapter\Twig\TwigEnvironment: it now implementsResetInterface, andTwigEnvironmentCompilerPasstags thetwigservice withkernel.reset(method: reset). This plugin replaces thetwigservice class withTwigDecorator, which extended the plainTwig\Environment— so the inheritedreset()was lost andServicesResetter(viaResetServicesListener, triggered after each handled message) crashed the worker.Fix
TwigDecoratornow extendsShopware\Core\Framework\Adapter\Twig\TwigEnvironment— the very class Shopware assigns to thetwigservice — instead ofTwig\Environment. This is exactly the patch suggested in the issue.Compatibility
reset()is inherited fromTwigEnvironment, soServicesResetterworks and the escape cache is cleared as Shopware intends.TwigEnvironmentalready exists with the same constructor signature (LoaderInterface $loader, array $options = []), and thekernel.resettag is not registered on thetwigservice there — no behaviour change.TwigDataCollectortype-hintsTwig\Environment, whichTwigEnvironmentextends, so the data collector wiring is unaffected.Verification
php -lpasses on all plugin source files.TwigDecoratorinherits a callablereset()(whatServicesResetterinvokes) and still collects template render data viarender()/getTemplateData().Fixes #85