[5.x]: Error when attempting to resave entries via terminal (nested elements issue)
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 3.6k
- Forks
- 705
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 134
Description
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
- Create entries with nested elements using CK Editor within a NeoField.
- Attempt to resave entries via terminal using php craft resave/entries.
- Observe the error related to nested elements and invalid owner ID.
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
- The issue seems to occur after nesting CK Editor snippets within NeoFields.
- Even after removing the nested entries and all revisions, the error persists.
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with craft\base\NestedElementTrait.php at line 158 and follow the resave path from craft\console\controllers\ResaveController.php through craft\services\Elements.php. Reproduce with php craft resave/entries using nested entries in a NeoField and inspect the Invalid owner ID path. Done means affected entries resave successfully without the exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100