Problem/Motivation

The overridden file system introduced in #3058063: Issue with setting permissions on a private bucket presents a regression in file upload widgets using ajax (e.g., using core's media library) and incorrectly implements the decorator pattern. There are alternative methods for forcing the bitmask on uploaded files that do not require overriding the file system.

Proximately, injecting the Settings service creates a serialization error ("Settings can not be serialized...") as the s3 file system service definition requires Settings. This could be avoided by using static methods on that service, however Drupal core is moving away from Settings in DI for this type of condition. See #2443351: Ensure that settings can't be serialized by not injecting them / replace stuff with container parameters..

Proposed resolution

Revert https://git.drupalcode.org/project/flysystem_s3/commit/f946cfb and use $settings['file_chmod_file'] or FlySystem's public_mask configuration option, instead.

Remaining tasks

Review/revert.

User interface changes

None.

API changes

None.

Data model changes

None.

Release notes snippet

n/a

CommentFileSizeAuthor
#2 3133318-2.patch646 bytesspadxiii
revert.patch3.65 KBbradjones1

Comments

bradjones1 created an issue. See original summary.

spadxiii’s picture

StatusFileSize
new646 bytes

Here is another patch that solves the serialization issue without reverting the whole patch.
Added DependencySerializationTrait, which solves the issue.

slasher13’s picture

Status: Needs review » Reviewed & tested by the community

Had the same problem (file upload widgets using ajax).
Before

LogicException: Settings can not be serialized. This probably means you are serializing an object that has an indirect reference to the Settings object. Adjust your code so that is not necessary.

Applied patch #2 and file upload works!

bradjones1’s picture

Adding DependencySerializationTrait does address this, however I still maintain that the addition of the new service isn't necessary and is a good candidate for a revert, to keep the implementation here as simple as possible.

bradjones1’s picture

Status: Reviewed & tested by the community » Needs review
jordandukart’s picture

So to move this issue along @bradjones1 what were you looking to see refined here or does there need to be discussion around how https://www.drupal.org/project/flysystem_s3/issues/3058063 can be accomplished without decorating? Definitely ran into a scenario with flysystem_s3 that hit https://www.drupal.org/project/drupal/issues/2896993 as well.

ericpugh’s picture

Since the new service created a new "major" bug, wouldn't it make the most sense to first revert that change, and then create a separate issue for handling private buckets with all the proposed resolutions from this thread?

jordandukart’s picture

I mean I'd like to see the above or at least some visibility / discussion to this. For the time being for the project I'm working on we are just nuking the decorator as we aren't using private buckets in our implementation as of current.

mangy.fox’s picture

As an aside - the reversion patch conflicts with https://www.drupal.org/project/flysystem_s3/issues/3159928, which is required for D9 use. Patch #2 does apply and fixes the issue though.

3cwebdev’s picture

I spent days troubleshooting an error that was causing media assets to fail when being inserted via the media widget with the below watchdog error. Patch #2 resolved the issue and allowed us to be able to insert new media assets again.

"LogicException: Settings can not be serialized. This probably means you are serializing an object that has an indirect reference to the Settings object. Adjust your code so that is not necessary"

leon kessler’s picture

I do agree with #4, decorating an entire service just to override some chmod settings seems like an unnecessary burden for this module.

However, setting $settings['file_chmod_file'] may not be a good solution for everyone, particularly those who are using a combination of different file systems. That's what the decorated service is able to do (only alter the chmod settings when it really needs to).

I couldn't find anything on flysystem's public_mask setting (no mention of it in either the flysystem module or on the flysystem docs/github). I did fine PortableVisibilityConverter, but this appears to be only on version 2/3 of Flysystem.

I would agree to revert the original change, but as this has now been in the module for almost 2 years now. I think it may be safer to keep things how they are and incorporate patch from #2.

  • Leon Kessler committed 9d8f970 on 2.0.x authored by SpadXIII
    Issue #3133318 by bradjones1, SpadXIII: Revert #3058063 - Regression on...
leon kessler’s picture

Status: Needs review » Needs work

Patch from #2 has now been merged in, this should now prevent errors when used with the media module.

However I will leave this issue open, in case anyone fancies resolving this in a way that doesn't require overriding the file system.

bradjones1’s picture

Status: Needs work » Fixed

I'm going to be bold and close this because it has run its course, however the decorator pattern here is plain incorrect. Decorators should not extend the class they are decorating, but rather wrap them. I ran into this in a rather insidious way, today, which I will document on a new issue.

To the extent something got fixed here I think also setting the status to Fixed will generate proper issue credit.

For the record I still don't like this really at all, but to Leon's point, this is part of the module now for quite a while and people depend on this functionality (e.g., me) even if the actual decorator implementation is incorrect. That, we can fix.

Status: Fixed » Closed (fixed)

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