craftcms / aws-s3

Amazon S3 volume type for Craft CMS.
https://plugins.craftcms.com/aws-s3
MIT License
61 stars 28 forks source link

Error with SVG when eager loading relations on already injected elements #106

Open robmcfadden opened 3 years ago

robmcfadden commented 3 years ago

Description

Eager loading works fine in all cases when using on a query with the with parameter, but if I eager load an assets field on an already injected element, I get an error in the debug toolbar on the frontend when that asset is an SVG (other file types seem to work as expected). It still loads the SVG on the page and doesn't give me an error there. It's isolated to the debug toolbar.

PHP Notice – yii\base\ErrorException
Trying to access array offset on value of type null

These assets are hosted on S3. I have not tested with locally hosted assets. Here's what I'm trying...

{# Works #}
{% set entry = craft.entries({
    section: 'home',
    with: 'assetsField',
}).one() %}
{{ svg(entry.assetsField[0]) }}

{# Doesn't work #}
{% do craft.app.elements.eagerLoadElements(
    className(entry),
    [entry],
    ['assetsField'],
) %}
{{ svg(entry.assetsField[0]) }}

Additional info

Screen Shot 2020-12-14 at 7 27 20 AM
brandonkelly commented 3 years ago

Can you post the stack trace that is displayed below the error?

robmcfadden commented 3 years ago

Interesting, just realized there's a bit more going on. This is the stack trace from the error that's in the DB tab there...

yii\base\ErrorException: Trying to access array offset on value of type null in /var/www/vendor/yiisoft/yii2-debug/src/views/default/panels/request/summary.php:8
Stack trace:
#0 /var/www/vendor/craftcms/cms/src/web/ErrorHandler.php(76): yii\base\ErrorHandler->handleError(8, 'Trying to acces...', '/var/www/vendor...', 8)
craftcms/cms#1 /var/www/vendor/yiisoft/yii2-debug/src/views/default/panels/request/summary.php(8): craft\web\ErrorHandler->handleError(8, 'Trying to acces...', '/var/www/vendor...', 8, Array)
craftcms/cms#2 /var/www/vendor/yiisoft/yii2/base/View.php(348): require('/var/www/vendor...')
craftcms/cms#3 /var/www/vendor/yiisoft/yii2/base/View.php(257): yii\base\View->renderPhpFile('/var/www/vendor...', Array)
craftcms/cms#4 /var/www/vendor/yiisoft/yii2/base/View.php(156): yii\base\View->renderFile('/var/www/vendor...', Array, NULL)
craftcms/cms#5 /var/www/vendor/yiisoft/yii2-debug/src/panels/RequestPanel.php(43): yii\base\View->render('panels/request/...', Array)
craftcms/cms#6 /var/www/vendor/yiisoft/yii2-debug/src/views/default/view.php(26): yii\debug\panels\RequestPanel->getSummary()
craftcms/cms#7 /var/www/vendor/yiisoft/yii2/base/View.php(348): require('/var/www/vendor...')
craftcms/cms#8 /var/www/vendor/yiisoft/yii2/base/View.php(257): yii\base\View->renderPhpFile('/var/www/vendor...', Array)
craftcms/cms#9 /var/www/vendor/yiisoft/yii2/base/View.php(156): yii\base\View->renderFile('/var/www/vendor...', Array, Object(yii\debug\controllers\DefaultController))
craftcms/cms#10 /var/www/vendor/yiisoft/yii2/base/Controller.php(409): yii\base\View->render('view', Array, Object(yii\debug\controllers\DefaultController))
craftcms/cms#11 /var/www/vendor/yiisoft/yii2-debug/src/controllers/DefaultController.php(127): yii\base\Controller->render('view', Array)
craftcms/cms#12 [internal function]: yii\debug\controllers\DefaultController->actionView('5fd8afa4873bd', 'elements')
craftcms/cms#13 /var/www/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
craftcms/cms#14 /var/www/vendor/yiisoft/yii2/base/Controller.php(180): yii\base\InlineAction->runWithParams(Array)
craftcms/cms#15 /var/www/vendor/yiisoft/yii2/base/Module.php(528): yii\base\Controller->runAction('view', Array)
craftcms/cms#16 /var/www/vendor/craftcms/cms/src/web/Application.php(274): yii\base\Module->runAction('debug/default/v...', Array)
craftcms/cms#17 /var/www/vendor/craftcms/cms/src/web/Application.php(577): craft\web\Application->runAction('debug/default/v...', Array)
craftcms/cms#18 /var/www/vendor/craftcms/cms/src/web/Application.php(253): craft\web\Application->_processActionRequest(Object(craft\web\Request))
craftcms/cms#19 /var/www/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
craftcms/cms#20 /var/www/public/index.php(21): yii\base\Application->run()
craftcms/cms#21 {main}

And I'm getting a different error if I go to the Request tab of...

yii\debug\FlattenException
Instances of craft\awss3\S3Client cannot be serialized

with stack trace of...

RuntimeException: Instances of craft\awss3\S3Client cannot be serialized in /var/www/vendor/aws/aws-sdk-php/src/AwsClient.php:275
Stack trace:
#0 [internal function]: Aws\AwsClient->__sleep()
craftcms/cms#1 /var/www/vendor/opis/closure/functions.php(20): serialize(Array)
craftcms/cms#2 /var/www/vendor/yiisoft/yii2-debug/src/LogTarget.php(66): Opis\Closure\serialize(Array)
craftcms/cms#3 /var/www/vendor/yiisoft/yii2-debug/src/LogTarget.php(136): yii\debug\LogTarget->export()
craftcms/cms#4 /var/www/vendor/yiisoft/yii2/log/Dispatcher.php(191): yii\debug\LogTarget->collect(Array, true)
craftcms/cms#5 /var/www/vendor/yiisoft/yii2/log/Logger.php(177): yii\log\Dispatcher->dispatch(Array, true)
craftcms/cms#6 [internal function]: yii\log\Logger->flush(true)
craftcms/cms#7 {main}
andris-sevcenko commented 3 years ago

@robmcfadden I was not able to reproduce this, but there are multiple dependant packages involved here that might have different versions. Is it possible to get your composer.json and composer.lock files, so I can work with the exact versions of all packages?

andris-sevcenko commented 3 years ago

In case you don't want that information public, you can just send it over to support@craftcms.com and reference this issue!

robmcfadden commented 3 years ago

@andris-sevcenko - Sent via email. Thanks for taking a look!