Assertion fails when using external stream wrappers (e.g. s3fs) in PublicFileIntegration

Created on 23 March 2025, 15 days ago
Updated 1 April 2025, 6 days ago

Problem/Motivation

The module drupal/entity_usage includes a hardcoded assumption that the public file system uses a local stream wrapper (LocalStream). This is reflected in the assertion:

assert($publicStream instanceof LocalStream);

However, when using external file systems (such as the drupal/s3fs module for Amazon S3), the public stream wrapper implements the generic StreamWrapperInterface but does not extend LocalStream. Therefore, the assertion fails and throws an exception, making the module incompatible with setups using external file storage.

Steps to reproduce

  1. Set up Drupal with the drupal/s3fs module and configure the public file system to use Amazon S3 instead of the local filesystem.
  2. Enable the entity_usage module.
  3. Access a URL referencing a public file.
  4. Observe that the site throws an error caused by the failed assertion:

assert($publicStream instanceof LocalStream);

Proposed resolution

Modify the assertion to validate the general interface rather than the specific local implementation, ensuring compatibility with external stream wrappers like drupal/s3fs. Update the line from:

assert($publicStream instanceof LocalStream);

to

assert($publicStream instanceof StreamWrapperInterface);

This general approach ensures broader compatibility across different storage backends.

Remaining tasks

  • Submit a patch or merge request with the proposed fix.
  • Test the fix thoroughly, both with local and external stream wrappers (e.g., s3fs).

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Active

Component

Code

Created by

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024