craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 635 forks source link

User can't open specific entry #9895

Closed Gerharbo closed 3 years ago

Gerharbo commented 3 years ago

Description

The user tries to open a specific page with a Matrix element. The user receives an Internal Server error message.

Stacktrace:

yii\base\ErrorException: Undefined array key 1 in /vendor/craftcms/cms/src/services/Matrix.php:1013 Stack trace: #0 /vendor/craftcms/cms/src/web/ErrorHandler.php(75): yii\base\ErrorHandler->handleError() #1 /vendor/craftcms/cms/src/services/Matrix.php(1013): craft\web\ErrorHandler->handleError() #2 /vendor/craftcms/cms/src/fields/Matrix.php(1026): craft\services\Matrix->mergeCanonicalChanges() #3 /vendor/craftcms/cms/src/base/Element.php(4007): craft\fields\Matrix->afterElementPropagate() #4 /vendor/craftcms/cms/src/elements/Entry.php(1670): craft\base\Element->afterPropagate() #5 /vendor/craftcms/cms/src/services/Elements.php(842): craft\elements\Entry->afterPropagate() #6 [internal function]: craft\services\Elements->craft\services{closure}() #7 /vendor/yiisoft/yii2/db/Connection.php(814): call_user_func() #8 /vendor/craftcms/cms/src/services/Elements.php(843): yii\db\Connection->transaction() #9 /vendor/craftcms/cms/src/controllers/EntriesController.php(678): craft\services\Elements->mergeCanonicalChanges() #10 /vendor/craftcms/cms/src/controllers/EntriesController.php(81): craft\controllers\EntriesController->_prepEditEntryVariables() #11 [internal function]: craft\controllers\EntriesController->actionEditEntry() #12 /vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array() #13 /vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams() #14 /vendor/craftcms/cms/src/web/Controller.php(190): yii\base\Controller->runAction() #15 /vendor/yiisoft/yii2/base/Module.php(534): craft\web\Controller->runAction() #16 /vendor/craftcms/cms/src/web/Application.php(277): yii\base\Module->runAction() #17 /vendor/yiisoft/yii2/web/Application.php(104): craft\web\Application->runAction() #18 /vendor/craftcms/cms/src/web/Application.php(262): yii\web\Application->handleRequest() #19 /vendor/yiisoft/yii2/base/Application.php(392): craft\web\Application->handleRequest() #20 /public/index.php(26): yii\base\Application->run() #21 {main}

The $localizedOwners in the function mergeCanonicalChanges() (https://github.com/craftcms/cms/blob/develop/src/services/Matrix.php#L946) is empty and therefore the owner can't be set on line 1013 (https://github.com/craftcms/cms/blob/develop/src/services/Matrix.php#L1013).

The query for $localizedOwners searches for the element in other sites, which is disabled for this entry type by default.

Steps to reproduce

No clear steps to reproduce this error. But if we add a date to the dateDeleted field in the elements table the function mergeCanonicalChanges() isn't called and the page works again.

Additional info

brandonkelly commented 3 years ago

Thanks for reporting. I found a way to reproduce this: when editing a draft (either a normal draft or a “provisional draft”), if the upstream entry had been enabled for a new site, and contained new Matrix blocks which needed to be merged into the draft.

Just fixed for the next release. To get the fix early, change your craftcms/cms requirement in composer.json to "dev-develop as 3.7.14" and run composer update.

Gerharbo commented 3 years ago

Hi @brandonkelly,

Thanks for the quick fix! And we can confirm: it's fixed!

roelvanhintum commented 3 years ago

@brandonkelly, i'm still seeing this exact error on 3.7.14 when just viewing a draft of an entry.

yii\base\ErrorException: Undefined array key 1
#22 /var/www/vendor/craftcms/cms/src/services/Matrix.php(1013): yii\base\ErrorHandler::handleError
#21 /var/www/vendor/craftcms/cms/src/web/ErrorHandler.php(81): craft\web\ErrorHandler::handleError
#20 /var/www/vendor/sentry/sentry/src/ErrorHandler.php(303): Sentry\ErrorHandler::handleError
#19 /var/www/vendor/craftcms/cms/src/services/Matrix.php(1013): craft\services\Matrix::mergeCanonicalChanges
#18 /var/www/vendor/craftcms/cms/src/fields/Matrix.php(1035): craft\fields\Matrix::afterElementPropagate
#17 /var/www/vendor/craftcms/cms/src/base/Element.php(4114): craft\base\Element::afterPropagate
#16 /var/www/vendor/craftcms/cms/src/elements/Entry.php(1670): craft\elements\Entry::afterPropagate
#15 /var/www/vendor/craftcms/cms/src/services/Elements.php(842): craft\services\Elements::craft\services\{closure}
#14 [internal](0): call_user_func
#13 /var/www/vendor/yiisoft/yii2/db/Connection.php(814): yii\db\Connection::transaction
#12 /var/www/vendor/craftcms/cms/src/services/Elements.php(843): craft\services\Elements::mergeCanonicalChanges
#11 /var/www/vendor/craftcms/cms/src/controllers/EntriesController.php(678): craft\controllers\EntriesController::_prepEditEntryVariables
#10 /var/www/vendor/craftcms/cms/src/controllers/EntriesController.php(81): craft\controllers\EntriesController::actionEditEntry
#9 [internal](0): call_user_func_array
#8 /var/www/vendor/yiisoft/yii2/base/InlineAction.php(57): yii\base\InlineAction::runWithParams
#7 /var/www/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\Controller::runAction
#6 /var/www/vendor/craftcms/cms/src/web/Controller.php(189): craft\web\Controller::runAction
#5 /var/www/vendor/yiisoft/yii2/base/Module.php(534): yii\base\Module::runAction
#4 /var/www/vendor/craftcms/cms/src/web/Application.php(277): craft\web\Application::runAction
#3 /var/www/vendor/yiisoft/yii2/web/Application.php(104): yii\web\Application::handleRequest
#2 /var/www/vendor/craftcms/cms/src/web/Application.php(262): craft\web\Application::handleRequest
#1 /var/www/vendor/yiisoft/yii2/base/Application.php(392): yii\base\Application::run
#0 /index.php(25): null

Specs:

Application Info
PHP version 8.0.11
OS version  Linux 4.15.0-147-generic
Database driver & version   MySQL 8.0.23
Image driver & version  GD 8.0.11
Craft edition & version Craft Pro 3.7.14
Yii version 2.0.43
Twig version    v2.14.7
Guzzle version  6.5.5
Plugins
Asset Usage 2.2.1
Buckaroo for Craft Commerce 1.1.0.1
Color Extractor 2.0.6.1
Craft Commerce  3.4.3
fortrabbit Object Storage Volume    2.1.0
Linkit  1.1.12.1
Maps    3.9.2
Redactor    2.8.8
Sentry SDK  1.1.2
SEOmatic    3.4.15
Super Table 2.6.8
Two-Factor Authentication   2.9.0
Vite    1.0.16
Gerharbo commented 3 years ago

@roelvanhintum it's not released yet. You can use the dev version:

Just fixed for the next release. To get the fix early, change your craftcms/cms requirement in composer.json to "dev-develop as 3.7.14" and run composer update.

brandonkelly commented 3 years ago

Craft 3.7.15 is out now with this fix.