Circular reference detected for service symfony mailer config override in multilingual sites

Created on 26 June 2023, over 1 year ago
Updated 16 July 2023, over 1 year ago

Problem/Motivation

Facing the following fatal error

In Container.php line 147:
                                                                               
  Circular reference detected for service "language_manager", path: "language  
  _request_subscriber -> language_manager -> config.factory -> symfony_mailer  
  .config_override -> plugin.manager.email_builder -> entity_type.manager ->   
  string_translation -> string_translator.locale.lookup".                      
                                                         

Steps to reproduce

Given that the "Drupal Symfony Mailer" was installed
And configured in a multilingual Drupal 10 website
When the admin install or uninstall modules
Then the "Circular reference detected for service" fatal error shows up

Proposed resolution

Manage the Circular reference of services in other ways

Remaining tasks

  • File an issue
  • Patch/MR fix
  • Test
  • Review

User interface changes

  • N/A

API changes

  • N/A

Data model changes

  • N/A
🐛 Bug report
Status

Fixed

Version

1.3

Component

Code

Created by

🇯🇴Jordan Rajab Natshah Jordan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Rajab Natshah
  • 🇺🇸United States themarkahrens

    We are experiencing the same issue with a multilingual site on Drupal 10.

    Circular reference detected for service "language_manager", path: "language_request_subscriber -> language_manager -> config.factory -> symfony_mailer.config_override -> plugin.manager.email_builder -> entity_type.manager -> string_translation -> string_translator.locale.lookup"

  • 🇧🇪Belgium weseze

    I have the same problem on a fresh install for Drupal 9.5.
    Marking as major since we can no longer install this module.

  • Same problem here with a multilingual site in drupal 10.0.9 when I enabled the module swiftmailer.

  • rolling back to 2479bcc8 resolved it for me. Looks like the fixes for https://www.drupal.org/project/symfony_mailer/issues/3367047 🐛 Caching bug enabling/disabling overrides Fixed caused the issue

  • 🇧🇪Belgium nonom Brussels

    The issue persists in Drupal 10.1.0 for a multilingual profile installation.

  • 🇯🇴Jordan Rajab Natshah Jordan

    Yes, you are right, Martinez

    Drupal ~10.1.0 for a multilingual profile installation

  • 🇬🇧United Kingdom adamps

    As far as I can see, the only part of the loop that we can break is this:
    symfony_mailer.config_override -> plugin.manager.email_builder

    MailerConfigOverride could fetch the email builder manager to a local variable inside buildCache().

    I'm not able to test this as I don't have any multilingual sites, so I hope someone else can help.

  • Status changed to Needs work over 1 year ago
  • 🇯🇴Jordan Rajab Natshah Jordan

    Tested:
    Only for Drupal 10 and Interface Translation + Language + Configuration Translation + Content Translation
    And only when having two or more languages.

    Not having the issue in Drupal 9

  • Status changed to Needs review over 1 year ago
  • 🇨🇴Colombia metallized

    As far as I can see, the only part of the loop that we can break is this:
    symfony_mailer.config_override -> plugin.manager.email_builder

    MailerConfigOverride could fetch the email builder manager to a local variable inside buildCache().

    I'm not able to test this as I don't have any multilingual sites, so I hope someone else can help.

    I tried to remove the plugin.manager.email_builder argument from symfony_mailer.config_override service, but the problem is that creating manually a instance of EmailBuilderManager needs a entityTypeManagerInterface argument, so now the circular reference is here, i think we must remove the EntityTypeManagerInterface from EmailBuilderManager.phpon line 72.

    What i unsderstand is that the locale requiresentity_type.manager to load translated configs and this modules try to override those configs, requiring the same dependency entity_type.manager so the circular reference happens.

    Don't know if is this correct, please review and let know how can i help you to make a fix, i am using Drupal 10 and locale modules.

  • 🇯🇴Jordan Rajab Natshah Jordan

    Is the following issue related?
    🐛 Circular reference on multi-language sites Fixed

  • 🇩🇪Germany kreatIL

    Same or similar issue here after upgrading to 1.3.0-rc1 on Drupal 9.5.10 and PHP 8.1.16
    Circular reference detected for service "entity_type.manager", path: "scheduler.manager -> date.formatter -> entity_type.manager -> string_translation -> string_translator.locale.lookup -> config.factory -> symfony_mailer.config_override -> plugin.manager.email_builder".

    It took me four hours to figure this out, because at first I assumed the error was caused by scheduler. Now I can definitely break it down to the update from symfony_mailer-1.3.0-beta2 to symfony_mailer-1.3.0-rc1.

  • 🇩🇪Germany kreatIL

    This is the error message that I get when I try to clear caches via admin ui:

    Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException: Circular reference detected for service "language_manager", path: "language_manager -> config.factory -> symfony_mailer.config_override -> plugin.manager.email_builder -> entity_type.manager -> string_translation -> string_translator.locale.lookup". in Drupal\Component\DependencyInjection\Container->get() (line 147 of core/lib/Drupal/Component/DependencyInjection/Container.php).
    
    Drupal\Component\DependencyInjection\Container->get('language_manager', 1) (Line: 434)
    Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
    Drupal\Component\DependencyInjection\Container->createService(Array, 'string_translator.locale.lookup') (Line: 177)
    Drupal\Component\DependencyInjection\Container->get('string_translator.locale.lookup', 1) (Line: 434)
    Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 273)
    Drupal\Component\DependencyInjection\Container->createService(Array, 'string_translation') (Line: 177)
    Drupal\Component\DependencyInjection\Container->get('string_translation', 1) (Line: 434)
    Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
    Drupal\Component\DependencyInjection\Container->createService(Array, 'entity_type.manager') (Line: 177)
    Drupal\Component\DependencyInjection\Container->get('entity_type.manager', 1) (Line: 434)
    Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
    Drupal\Component\DependencyInjection\Container->createService(Array, 'plugin.manager.email_builder') (Line: 177)
    Drupal\Component\DependencyInjection\Container->get('plugin.manager.email_builder', 1) (Line: 434)
    Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
    Drupal\Component\DependencyInjection\Container->createService(Array, 'symfony_mailer.config_override') (Line: 177)
    Drupal\Component\DependencyInjection\Container->get('symfony_mailer.config_override', 1) (Line: 434)
    Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 273)
    Drupal\Component\DependencyInjection\Container->createService(Array, 'config.factory') (Line: 177)
    Drupal\Component\DependencyInjection\Container->get('config.factory', 1) (Line: 434)
    Drupal\Component\DependencyInjection\Container->resolveServicesAndParameters(Array) (Line: 237)
    Drupal\Component\DependencyInjection\Container->createService(Array, 'language_manager') (Line: 177)
    Drupal\Component\DependencyInjection\Container->get('language_manager') (Line: 613)
    Drupal::languageManager() (Line: 479)
    token_tokens('log', Array, Array, Array, Object)
    call_user_func_array(Object, Array) (Line: 426)
    Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'token') (Line: 405)
    Drupal\Core\Extension\ModuleHandler->invokeAllWith('tokens', Object) (Line: 433)
    Drupal\Core\Extension\ModuleHandler->invokeAll('tokens', Array) (Line: 359)
    Drupal\Core\Utility\Token->generate('log', Array, Array, Array, Object) (Line: 241)
    Drupal\Core\Utility\Token->doReplace(1, '[[log:created]] [[log:level]] [[log:channel]] [client: [log:ip], [log:user]] [log:location] [log:message]', Array, Array, Object) (Line: 191)
    Drupal\Core\Utility\Token->replace('[[log:created]] [[log:level]] [[log:channel]] [client: [log:ip], [log:user]] [log:location] [log:message]', Array, Array, Object) (Line: 223)
    Drupal\filelog\Logger\FileLog->render(3, '%type: @message in %function (line %line of %file).', Array) (Line: 159)
    Drupal\filelog\Logger\FileLog->log(3, '%type: @message in %function (line %line of %file).', Array) (Line: 127)
    Drupal\Core\Logger\LoggerChannel->log(3, '%type: @message in %function (line %line of %file).', Array) (Line: 70)
    Drupal\Core\EventSubscriber\ExceptionLoggingSubscriber->onError(Object) (Line: 97)
    Drupal\Core\EventSubscriber\ExceptionLoggingSubscriber->onException(Object, 'kernel.exception', Object)
    call_user_func(Array, Object, 'kernel.exception', Object) (Line: 142)
    Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.exception') (Line: 229)
    Symfony\Component\HttpKernel\HttpKernel->handleThrowable(Object, Object, 1) (Line: 92)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
    Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
    Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
    
  • 🇩🇪Germany kreatIL

    Forwarding to dev-1.x 9b1509d does not solve it.

  • 🇩🇪Germany Anybody Porta Westfalica

    Same here! Happened when we uninstalled the "reroute" module, but that may be unrelated.

  • 🇮🇹Italy trickfun

    I think this error prevent sending mail with webform.
    I can send mail with symfony test but not with webform.

    I downgrade to 1.2.1 and all works fine.
    Thank you

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    6 pass
  • @metallized opened merge request.
  • 🇨🇴Colombia metallized

    I think this is a temporary fix, please tell me what else we can do.

  • Status changed to Needs work over 1 year ago
  • 🇬🇧United Kingdom adamps

    @metallized Many thanks it is the only possible fix I can see - not just temporary.

    Please can you put the formatting back how it was in symfony_mailer.services.yml and I will commit it (arguments all on a single line and in single quotes - it's the same in core.services.xml).

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    6 pass
  • Status changed to Needs review over 1 year ago
  • 🇬🇧United Kingdom adamps

    Thanks for the updated patch. Key question: does this fix the bug? Please can people try it and report back?

    EmailBuilderManager uses entity_type.manager - if we remove that we will break some things.

    My idea with the current patch is MailerConfigOverride will only load EmailBuilderManager when moduleHandler->isLoaded() is TRUE. For the very early calls to get config in middleware, the loading will be skipped. If it's still broken then we didn't wait long enough.

  • 🇬🇧United Kingdom adamps

    I installed some language modules on a test site, then I could hit this bug. I applied the patch from #26 and the problem was fixed. So the patch seems good for me.

  • Status changed to RTBC over 1 year ago
  • 🇩🇪Germany kreatIL

    I can confirm patch #25 fixes the error. Thank you @metallized

  • Status changed to Fixed over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    6 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    6 pass
  • 🇬🇧United Kingdom adamps

    Great thanks everyone

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024