Problem/Motivation

Drupal 9.3 has an incompatibility with S3FS 8.x-3.0-beta3 due to a change to the "asset.css.optimizer" service described here https://www.drupal.org/node/2940031

TypeError: Argument 1 passed to Drupal\s3fs\Asset\S3fsCssOptimizer::__construct() must implement interface Drupal\Core\Config\ConfigFactoryInterface, instance of Drupal\Core\File\FileUrlGenerator given, called in /var/www/webroot/core/lib/Drupal/Component/DependencyInjection/Container.php on line 262 in Drupal\s3fs\Asset\S3fsCssOptimizer->__construct() (line 26 of /var/www/webroot/modules/contrib/s3fs/src/Asset/S3fsCssOptimizer.php).

It will crash with WSOD on page load and error on drush without remediation except to omit the S3FS configuration from settings.php.

Steps to reproduce

Upgrade to Core 9.3 and then try to use a configured previously working S3FS configuration.

Proposed resolution

Update S3fsCssOptimizer to use the new CssOptimizer's expected FileUrlGeneratorInterface instead of the ConfigFactoryInterface

Issue fork s3fs-3253414

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

stevenlafl created an issue. See original summary.

stevenlafl’s picture

StatusFileSize
new1.49 KB

Here is a patch for 8.x-3.0-beta3

cmlara’s picture

Status: Active » Needs work

I’m going to have to think on this one. (Sending from phone, not looked at code fully)

I don’t think we can just roll this patch into the existing release as the patch as is will likely break compatibility with older Drupal releases.

Need to sit down at console to look. We may just want to override the service deceleration for now and accept that we have a deprecated call or expand it to if the service exists optionally pass on the new file creation service.

And of course this is code that isn’t well exercised by tests so It did not show up when I ran https://www.drupal.org/pift-ci-job/2252746 against D9.3.0-beta1 (note to self start working on the 4.x tests )

Minor mitigation: I believe this should only impact sites with public:// takeover enabled

darvanen’s picture

Version: 8.x-3.0-beta3 » 8.x-3.x-dev
Status: Needs work » Needs review
StatusFileSize
new6 KB

This should be 8.9.x compatible, sorry I can't give an interdiff, I started from scratch.

I found that using the injected file_url_generator service at line 60 of S3fsCssOptimizer broke the test because it changed the output. Suggest that be a follow-up issue.

Status: Needs review » Needs work

The last submitted patch, 5: 3253414-5.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

darvanen’s picture

Status: Needs work » Needs review
StatusFileSize
new1.13 KB
new5.78 KB

Bugger.

Here's a less ambitious version that doesn't introduce the (very new) interface to S3fs.

I put the parent call in to trigger the deprecation message so we don't lose track of it, happy for that to disappear if need be.

cmlara’s picture

StatusFileSize
new2.49 KB

Quick mock addition to #7 to allow tests to pass with D9.3.

Discussed on slack, this is intended to be a 'fast patch' to prevent WSOD for D9.3 users, we will come back and do this right to use the new service.

We can't just inject the service as done in #5 due to issues seen in #3038524: s3fs, cdn, advagg integration

Thanks to @darvanen for working this out to get us to a temp fix for all Drupal versions s3fs currently lists as supported and @stevenlafl for the quick and detailed report.

  • cmlara committed 40acad1 on 8.x-3.x authored by darvanen
    Issue #3253414 by stevenlafl, darvanen: Incompatibility with Drupal 9.3
    
cmlara’s picture

Assigned: stevenlafl » Unassigned
Priority: Critical » Normal
StatusFileSize
new1.36 KB

Attaching missing interdiff from #8.

Released 8.x-3.0-alpha4 with #8 included.

Downgrading to normal now that we have a stopgap measure in place.

I'm going to leave this issue open for now as a note that we still have more to work on.

cmlara’s picture

StatusFileSize
new8.93 KB

Attached is a more comprehensive version that allows us to utilize the new service (avoiding deprecation warnings) while retaining backwards compatibility with older versions of Drupal.

Honestly looking at this I believe that with regards to rewriteFileURI() we should do one of the following:

  • Duplicate it to S3fsAdvAggSubscriber::
  • Convert it to a trait to allow multiple uses.
  • Make it as part of a helper service
  • Allow it to be accessible via a public decorator of the asset.css.optimizer service.

All of those options except full duplication may require a decent rewrite to S3fsCssOptimizer::. I'm not really fond of duplicating the code unnecessarily either making a trait seem like a good idea however that too may require some rewriting.

Additionally given https://www.drupal.org/about/core/policies/core-change-policies/drupal-8...

developers should generally assume that implementations of classes will change, and that they should not inherit from classes in the system, or be prepared to update code for changes if they do.

Along with

The constructor for a service object (one in the container), plugin, or controller is considered internal unless otherwise marked, and may change in a minor release. These are objects where developers are not expected to call the constructor directly in the first place.

I think there are a number of areas in the code (CSS optimizer, Download Controller, etc) that we should consider avoiding inheriting and instead duplicate the code so that we have better control. This however is much more than I want to change about s3fs in the 3.x release at this time given where it is in the lifecycle and i suspect may be better done as part of the 4.x initiative.

I'm not really sure we should be replacing the class of the 'asset.css.optimizer' service instead of decorating the service (even if we never call the parent service) to reduce the risk of ever hitting a time where some other module considers doing the same or core makes a constructor change. Decorating priority would become a factor though making such a change more risky.

So in summation:
This could be better, but lets consider this patch for 3.x and focus on doing better in 4.x.

No interdiff due to a new commit base.

Happy holidays all, not expecting any comments from anyone this week, we are in a stable spot this can wait as a lower priority.

darvanen’s picture

@dww would say "we haven't yet reached the rule of 3" and I'm inclined to agree, particularly because, as you say, a lot of work is going into 4.x right now.

I agree that 4.x is also the place to be considering architectural changes, not here.

  • cmlara committed 159f80a on 8.x-3.x
    Issue #3253414 by stevenlafl, darvanen: Incompatibility with Drupal 9.3...
cmlara’s picture

Status: Needs review » Fixed

Good point on the rule of 3, jumping ahead on it is what makes this portion of the code such a mess when it it perhaps could of been simpler.

Committed the revised patch and closing for now. Will pickup the cleanup in the 4.x branch.

Status: Fixed » Closed (fixed)

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