Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x]: Local image source is deleted before transformation has started #14100

Closed
kringkaste opened this issue Jan 3, 2024 · 2 comments
Closed
Assignees

Comments

@kringkaste
Copy link
Contributor

What happened?

Description

After upgrading from 4.4.x to 4.5.13 we have an issue with generating transformations from assets stored on a S3 bucket. We get the following error:

[x.x.x.x][1][-][error][craft\errors\ImageTransformException] craft\errors\FsObjectNotFoundException: The file "test-image.jpg" does not exist. in /mnt/dlfnova/htdocs/vendor/craftcms/cms/src/helpers/ImageTransforms.php:220
Stack trace:
#0 /mnt/dlfnova/htdocs/vendor/craftcms/cms/src/helpers/ImageTransforms.php(423): craft\helpers\ImageTransforms::getLocalImageSource(Object(craft\elements\Asset))
#1 /mnt/dlfnova/htdocs/vendor/craftcms/cms/src/imagetransforms/ImageTransformer.php(378): craft\helpers\ImageTransforms::generateTransform(Object(craft\elements\Asset), Object(craft\models\ImageTransform), Object(Closure), NULL)
[...]

We debugged the problem on the stage environment and could identify the

// And delete it after the request, if nobody wants it.
if (Craft::$app->getConfig()->getGeneral()->maxCachedCloudImageSize == 0) {
    FileHelper::deleteFileAfterRequest($imageSourcePath);
}

code block as the source of the issue. Our general config for maxCachedCloudImageSize is 0 and the downloaded asset seems to be deleted immediately so the check in line 220

if (!is_file($imageSourcePath)) {
    throw new FsObjectNotFoundException("The file \"{$asset->getFilename()}\" does not exist.");
}

throw the exception above. When we disable maxCachedCloudImageSize in the config, everything works fine and the transformations were generated.

As we can see in the file history, there were changes in 4.5.11. Maybe this is a new issue introduced with these changes.

Steps to reproduce

  1. Set maxCachedCloudImageSize to 0.
  2. Have a asset.getUrl('transformation') in a template.
  3. Render the template.

Expected behavior

Generate asset transformation.

Actual behavior

Throws exception.

Craft CMS version

4.5.13

PHP version

8.1.18

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@kringkaste kringkaste changed the title [4.x]: Local image source is delete before transformation has started [4.x]: Local image source is deleted before transformation has started Jan 3, 2024
@i-just i-just self-assigned this Jan 5, 2024
@i-just
Copy link
Contributor

i-just commented Jan 5, 2024

Hi, thanks for getting in touch and for all the info!
I can replicate this if I also have generateTransformsBeforePageLoad set to true.

As we can see in the file history, there were changes in 4.5.11. Maybe this is a new issue introduced with these changes.

Yes, that’s it.

I raised a PR to address this.

@brandonkelly
Copy link
Member

Craft 4.5.15 and 4.6.0 are out with a fix for this. Thanks again for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants