Problem/Motivation

Since Drupal 11.4, likely due to changes in the module install flow related to #3416522 and its follow-ups,, the ModuleInstaller::doInstall() method registers stream wrappers (line 429) at a point during module installation where \Drupal::getContainer() may still reference the old service container - before \Drupal::setContainer() is called with the newly compiled container that includes the module's services.

AvPortalStreamWrapper::__construct() eagerly calls \Drupal::service('media_avportal.client'). When the stream wrapper is instantiated during module installation, this service does not yet exist in the active container, resulting in:

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException:
You have requested a non-existent service "media_avportal.client".

This is also related to #3416735: Stream wrappers not registered when installing module's default config.

Steps to reproduce

  1. Install Drupal 11.4+ with the minimal profile
  2. Run drush pm:enable media_avportal --yes
  3. Observe the ServiceNotFoundException for media_avportal.client

Proposed resolution

Lazy-load the media_avportal.client service instead of resolving it in the constructor. Add a getAvPortalClient() method that resolves the service on first use, and replace the direct property access in stream_open().

  public function __construct() {
    $this->configuration = \Drupal::configFactory()->get('media_avportal.settings');
  }

  protected function getAvPortalClient(): AvPortalClientInterface {
    if (!isset($this->avPortalClient)) {
      $this->avPortalClient = \Drupal::service('media_avportal.client');
    }
    return $this->avPortalClient;
  }

And in stream_open():

-      $response = $this->avPortalClient->resourceRequestByUri($this->uri);
+      $response = $this->getAvPortalClient()->resourceRequestByUri($this->uri);

Remaining tasks

  • Review and commit the patch
  • Verify the fix on Drupal 11.4

User interface changes

None.

API changes

None. The $avPortalClient property remains available for subclasses. A new protected method getAvPortalClient() is added.

Data model changes

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

lisotton created an issue. See original summary.

lisotton’s picture

Assigned: lisotton » Unassigned
Status: Active » Needs review

joevagyok made their first commit to this issue’s fork.

gpietrzak’s picture

After the changes it looks ok

  • joevagyok committed 26c178df on 2.x authored by lisotton
    Issue #3608940: Lazy load media_avportal.client in AvPortalStreamWrapper
    
joevagyok’s picture

Status: Needs review » Fixed

Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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