craftcms / cms

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

[5.x]: Error when attempting to resave entries via terminal (nested elements issue) #15819

Open alexanderbuergin opened 5 days ago

alexanderbuergin commented 5 days ago

What happened?

Description

We encountered an issue when trying to resave entries through the terminal. The process fails with an error indicating that nested elements cannot be saved, specifically due to the parent not being assigned correctly. The error seems to occur when we nest entries in a NeoField using CK Editor. After removing the CK Editor entry snippets from the field, the issue persists, even after deleting all revisions.

The command we executed was: php craft resave/entries

Output:

Resaving 1463 entries ...
    - [1/1463] Resaving Content Call Small (2021765) ... Exception 'yii\base\InvalidConfigException' with message 'Invalid owner ID: 2021764'

in /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/craftcms/cms/src/base/NestedElementTrait.php:158

Stack trace:

 php craft resave/entries
Resaving 1463 entries ...
    - [1/1463] Resaving Content Call Small (2021765) ... Exception 'yii\base\InvalidConfigException' with message 'Invalid owner ID: 2021764'

in /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/craftcms/cms/src/base/NestedElementTrait.php:158

Stack trace:
#0 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/craftcms/cms/src/base/NestedElementTrait.php(203): craft\elements\Entry->getPrimaryOwner()
#1 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/craftcms/cms/src/helpers/ElementHelper.php(553): craft\elements\Entry->getOwner()
#2 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/putyourlightson/craft-blitz/src/services/RefreshCacheService.php(279): craft\helpers\ElementHelper::isDraftOrRevision(Object(craft\elements\Entry))
#3 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/putyourlightson/craft-blitz/src/Blitz.php(387): putyourlightson\blitz\services\RefreshCacheService->isRefreshableElement(Object(craft\elements\Entry))
#4 [internal function]: putyourlightson\blitz\Blitz->putyourlightson\blitz\{closure}(Object(craft\events\MultiElementActionEvent))
#5 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Object(Closure), Object(craft\events\MultiElementActionEvent))
#6 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/yiisoft/yii2/base/Component.php(650): yii\base\Event::trigger('craft\\services\\...', 'beforeResaveEle...', Object(craft\events\MultiElementActionEvent))
#7 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/craftcms/cms/src/services/Elements.php(1581): yii\base\Component->trigger('beforeResaveEle...', Object(craft\events\MultiElementActionEvent))
#8 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/craftcms/cms/src/services/Elements.php(1221): craft\services\Elements->craft\services\{closure}()
#9 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/craftcms/cms/src/services/Elements.php(1566): craft\services\Elements->ensureBulkOp(Object(Closure))
#10 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/craftcms/cms/src/console/controllers/ResaveController.php(630): craft\services\Elements->resaveElements(Object(craft\elements\db\EntryQuery), true, true, false, false)
#11 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/craftcms/cms/src/console/controllers/ResaveController.php(460): craft\console\controllers\ResaveController->_resaveElements(Object(craft\elements\db\EntryQuery))
#12 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/craftcms/cms/src/console/controllers/ResaveController.php(399): craft\console\controllers\ResaveController->resaveElements('craft\\elements\\...', Array)
#13 [internal function]: craft\console\controllers\ResaveController->actionEntries()
#14 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#15 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#16 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('entries', Array)
#17 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/craftcms/cms/src/console/ControllerTrait.php(89): yii\console\Controller->runAction('entries', Array)
#18 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/craftcms/cms/src/console/Controller.php(216): craft\console\Controller->traitRunAction('entries', Array)
#19 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/yiisoft/yii2/base/Module.php(552): craft\console\Controller->runAction('entries', Array)
#20 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('resave/entries', Array)
#21 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('resave/entries', Array)
#22 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('resave/entries', Array)
#23 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/craftcms/cms/src/console/Application.php(122): yii\console\Application->handleRequest(Object(craft\console\Request))
#24 /home/brandch/public_html/brand/brandSystem/brandWebsite/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
#25 /home/brandch/public_html/brand/brandSystem/brandWebsite/craft(24): yii\base\Application->run()

Steps to reproduce

Expected behavior

The entries should resave successfully, even after removing CK Editor content and deleting revisions.

Actual behavior

The process fails with an error related to invalid owner IDs for nested elements.

Additional Information

Craft CMS version

5.4

PHP version

8.3

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

-

i-just commented 4 days ago

Hi, thanks for getting in touch! I’m not able to replicate this. Any chance you could send over your composer.json, composer.lock and database export to support@craftcms.com so that we can try to reproduce and dig deeper?