Fix Circular Reference by Removing Autowire and Minimizing Dependencies in modeler_api.service

Created on 24 July 2025, 3 days ago

Problem/Motivation

Encountering a fatal ServiceCircularReferenceException in Drupal ~11.2.0 with ECA ~3.0, but not in Drupal ~10.5.0 with ECA ~2.0.

Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException: Circular reference detected for service "router.route_provider", path: "options_request_listener -> router.route_provider -> cache_tags.invalidator -> plugin.manager.block -> logger.channel.default -> Drupal\Core\Logger\LoggerChannelFactoryInterface -> logger.syslog -> Drupal\modeler_api\Hook\EntityHooks -> modeler_api.service"

This error is triggered when Drupal attempts to resolve a deep dependency chain involving logging and block plugins, which loops back into the modeler_api.service.

Proposed resolution

  • Remove autowiring from modeler_api.service.
  • Strip all constructor arguments to avoid eager resolution of services.
  • Use lazy-loading patterns (like \Drupal::service() or service locators) inside the methods instead of injecting services directly.
  • Keep the service definition minimal and constructor-free to avoid circular dependency chains.

This approach ensures the service can be loaded safely without invoking Symfony’s circular reference protection.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan

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

Merge Requests

Comments & Activities

  • Issue created by @Rajab Natshah
  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan
  • Pipeline finished with Failed
    3 days ago
    Total: 136s
    #555921
  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Thank you @rajab natshah for reporting this and proposing a solution. I'm surprised this is happening in your installation, since I'm using Drupal 11.2 and ECA 3 on many sites, including the development environment. And I haven't seen that issue before. Before we give in on this one, can we somehow find out why this is happening?

  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan

    I have a big stack of modules and CIs.
    + multiple languages
    For exmaple scheduler, paragraphs, consumer.

    Fined out

    In Container.php line 147:
                                                                                                                                                                                     
      Circular reference detected for service "Drupal\Core\Logger\LoggerChannelFactoryInterface", path: "scheduler.manager -> logger.channel.scheduler -> Drupal\Core\Logger\Logger  
      ChannelFactoryInterface -> logger.syslog -> Drupal\modeler_api\Hook\EntityHooks -> modeler_api.service -> router.route_provider -> cache_tags.invalidator -> plugin.manager.b  
      lock -> logger.channel.default".                                                                                                                                               
                                       
    
    In DefinitionErrorExceptionPass.php line 48:
                                                                                                                                                                                     
      [Symfony\Component\DependencyInjection\Exception\RuntimeException]                                                                                                             
      Cannot autowire service "Drupal\modeler_api\Hook\EntityHooks": argument "$modelerApiService" of method "__construct()" references class "Drupal\modeler_api\Api" but no such   
      service exists. You should maybe alias this class to the existing "modeler_api.service" service. 
    
    In DefinitionErrorExceptionPass.php line 48:
                                                                                                                                                                                     
      [Symfony\Component\DependencyInjection\Exception\RuntimeException]                                                                                                             
      Cannot autowire service "Drupal\modeler_api\Hook\EntityHooks": argument "$modelerApiService" of method "__construct()" references class "Drupal\modeler_api\Api" but no such   
      service exists. You should maybe alias this class to the existing "modeler_api.service" service.  
    

    Still testing the first draft fix with AI

  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan

    Impressive module, by the way (thanks for working on it).
    Could a new 2.0.x branch help?
    So we don't manage old and new ways within the same codebase.

    Drupal ~11.2.0 is doing things a new way, and contrib modules haven't caught up to it yet.
    Trying to find a smoother mechanism and method for the update process.

  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan

    Attached a static modeler_api--2025-07-24--3537810--mr-8.patch file, for this point of MR8.
    To be used with Composer Patches and Drupal ~11.2.0

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    Originally, this module was only meant to work for Drupal 11.2 and later. For several reasons, we opened it up to be available for Drupal 10.4 as well, something I wasn't keen to do, but that's what it is now. Therefore, just now already opening another branch is not a priority. Let's avoid that if not absolutely necessary.

    Still, I can't reproduce the issue, neither on 11.2 nor on earlier versions. So, I don't know exactly what we should be doing as it doesn't seem to be a general issue. I think before we can make further decisions, we need some reproducible instructions.

  • πŸ‡©πŸ‡ͺGermany jurgenhaas Gottmadingen

    And BTW, uploading patches for composer is really bad practice. The DA makes it clear wherever they can, there is no guarantee that those files will be available. Patches have to be downloaded from the MR locally and applied from there,

  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan

    Noted;
    Thanks for following up on this issue. As I said, we have a big stack of modules.
    I did not change the status of the issue to needs review yet, but you started reviewing. ( Thank you for being on the spot )
    For sure, Next time, I will add the Steps to reproduce when filing issues. I thought that when I sat on the final fix, I would add them.

    Let's rest this issue. ( We manage a local patching system in all projects, only shared to make it public for search)
    We added the Modeler API module to our products. with ECA.

    It is the standard for my team to Managing Only Local Patches for Projects

    Varbase Patches
    When working with Drupal, it's common to patch core or contrib modules to fix bugs or review code changes before they're officially released. While applying patches via patch files is straightforward, using GitLab's merge request (MR) feature presents a challenge due to unstable diff URLs.

    As multiple commits are added to an MR, generating a stable patch file becomes complex. To create a static patch file for an MR at a specific point in time, simply set up a 'patches' folder next to your root composer.json. Download the .diff or .patch into this folder and utilize composer-patches to apply it seamlessly.

    Varbase Patches has the list of needed patches for Varbase used packages with Composer Patches.

    I attended a number of TUF meetings in the past couple of years and asked Trishank, and Marina about the best options to manage patches, which they listed ( Local Patches, Private/public patching storage - but with stamped key/permittion, or add them in the patches branch )
    No PRs/MRs, and you are right about other hosted patches in Drupal.
    Better to move all to Local Patches, or private patching storage system.

    Varbase has the Drush Command to Clean up Any Merge Request Patches

    Drupal CMS switched to use Local Patching system!! too
    https://git.drupalcode.org/project/drupal_cms/-/tree/2.x/patches?ref_typ...
    https://git.drupalcode.org/project/drupal_cms/-/commit/318f64b7126208d15...
    https://git.drupalcode.org/project/drupal_cms/-/blob/2.x/dev.composer.js...

  • πŸ‡―πŸ‡΄Jordan Rajab Natshah Jordan

    JΓΌrgen, moving to follow with your tip.
    To use our patching storage. not to keep uploading/attaching a copy of MRs.
    Thanks, I cooked your remark overnight, and you are right on this.

    Back to the issue
    We are using ECA, BPMN.iO with Modeler API in both Drupal 10.5.0 for some old projects, and Drupal ~11.2.0 too

Production build 0.71.5 2024