Skip to content

Fix messenger worker crash: extend Shopware's TwigEnvironment in TwigDecorator - #87

Closed
shyim wants to merge 1 commit into
mainfrom
cursor/fix-twig-decorator-reset-3117
Closed

shyim wants to merge 1 commit into
mainfrom
cursor/fix-twig-decorator-reset-3117

Conversation

@shyim

@shyim shyim commented Sep 15, 2026

Copy link
Copy Markdown
Member

Problem

On Shopware >= 6.7.14.0 (any version containing shopware/shopware#19304), async messenger workers crash after handling a message:

In ServicesResetter.php line 60:
  [Symfony\Component\ErrorHandler\Error\UndefinedMethodError]
  Attempted to call an undefined method named "reset" of class "Frosh\DevelopmentHelper\Component\Profiler\TwigDecorator".

Shopware PR shopware/shopware#19304 moved the Twig escape-cache clearing onto Shopware\Core\Framework\Adapter\Twig\TwigEnvironment: it now implements ResetInterface, and TwigEnvironmentCompilerPass tags the twig service with kernel.reset (method: reset). This plugin replaces the twig service class with TwigDecorator, which extended the plain Twig\Environment — so the inherited reset() was lost and ServicesResetter (via ResetServicesListener, triggered after each handled message) crashed the worker.

Fix

TwigDecorator now extends Shopware\Core\Framework\Adapter\Twig\TwigEnvironment — the very class Shopware assigns to the twig service — instead of Twig\Environment. This is exactly the patch suggested in the issue.

Compatibility

  • 6.7.14.0+: reset() is inherited from TwigEnvironment, so ServicesResetter works and the escape cache is cleared as Shopware intends.
  • 6.6.x / 6.7.x < 6.7.14: TwigEnvironment already exists with the same constructor signature (LoaderInterface $loader, array $options = []), and the kernel.reset tag is not registered on the twig service there — no behaviour change.
  • TwigDataCollector type-hints Twig\Environment, which TwigEnvironment extends, so the data collector wiring is unaffected.

Verification

  • php -l passes on all plugin source files.
  • Ran a harness stubbing the 6.7.14.0 class hierarchy: TwigDecorator inherits a callable reset() (what ServicesResetter invokes) and still collects template render data via render()/getTemplateData().

Fixes #85

Open in Web Open in Cursor 

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>
@shyim shyim closed this Sep 15, 2026
@shyim
shyim deleted the cursor/fix-twig-decorator-reset-3117 branch September 15, 2026 08:04
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.

Messenger workers crash with UndefinedMethodError: TwigDecorator::reset() on Shopware >= 6.7.x

2 participants