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
- Install Drupal 11.4+ with the
minimalprofile - Run
drush pm:enable media_avportal --yes - 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.
Issue fork media_avportal-3608940
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
Comment #3
lisotton commentedComment #5
gpietrzakAfter the changes it looks ok
Comment #7
joevagyok commentedThanks!