Skip to content

[5.x]: Invalid owner id on isElementDraftOrRevision() call #16359

@zsavajji

Description

@zsavajji

What happened?

Hi, we are building a multi-site website with Craft, we're in development since beta, and we're now trying to propagate entries to a new site instance, since we're using sites as per country variations.
I wrote a custom module, which i successfully used in Craft 4.x to propagate entries from a given site to a target one, it works ok for a lot of entries, but some Matrix fields throw "Invalid owner ID" when invoking ElementHelper::isDraftOrRevision().

The behavior is unrelated to the element save phase.

I also got for one particular entry the Call to a member function getFieldById() on null error, and it seems related to the missing owner id error, since it comes from NestedElementTrait.php:243 class in getField(), which errors on $this->getOwner()?->getFieldLayout()->getFieldById($this->fieldId)

Do you have any idea on what could be going on and on how to correct this behavior?
The customer has already done a big part of the data entry and database corruption is really suboptimal at this stage.

Thanks in advance!

yii\base\InvalidConfigException: Invalid owner ID: 253 in /Users/andreafaggin/projects/lnproject-be/vendor/craftcms/cms/src/base/NestedElementTrait.php:166
Stack trace:
#0 /Users/andreafaggin/projects/lnproject-be/vendor/craftcms/cms/src/base/NestedElementTrait.php(211): craft\elements\Entry->getPrimaryOwner()
#1 /Users/andreafaggin/projects/lnproject-be/vendor/craftcms/cms/src/helpers/ElementHelper.php(553): craft\elements\Entry->getOwner()
#2 /Users/andreafaggin/projects/lnproject-be/vendor/craftcms/cms/src/helpers/ElementHelper.php(555): craft\helpers\ElementHelper::isDraftOrRevision(Object(craft\elements\Entry))
#3 /Users/andreafaggin/projects/lnproject-be/modules/sitepropagations/console/controllers/PropagateController.php(90): craft\helpers\ElementHelper::isDraftOrRevision(Object(craft\elements\Entry))
#4 [internal function]: modules\sitepropagations\console\controllers\PropagateController->actionCopyLocales()
#5 /Users/andreafaggin/projects/lnproject-be/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#6 /Users/andreafaggin/projects/lnproject-be/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#7 /Users/andreafaggin/projects/lnproject-be/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('copy-locales', Array)
#8 /Users/andreafaggin/projects/lnproject-be/vendor/craftcms/cms/src/console/ControllerTrait.php(88): yii\console\Controller->runAction('copy-locales', Array)
#9 /Users/andreafaggin/projects/lnproject-be/vendor/craftcms/cms/src/console/Controller.php(216): craft\console\Controller->traitRunAction('copy-locales', Array)
#10 /Users/andreafaggin/projects/lnproject-be/vendor/yiisoft/yii2/base/Module.php(552): craft\console\Controller->runAction('copy-locales', Array)
#11 /Users/andreafaggin/projects/lnproject-be/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('site-propagatio...', Array)
#12 /Users/andreafaggin/projects/lnproject-be/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('site-propagatio...', Array)
#13 /Users/andreafaggin/projects/lnproject-be/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('site-propagatio...', Array)
#14 /Users/andreafaggin/projects/lnproject-be/vendor/craftcms/cms/src/console/Application.php(122): yii\console\Application->handleRequest(Object(craft\console\Request))
#15 /Users/andreafaggin/projects/lnproject-be/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
#16 /Users/andreafaggin/projects/lnproject-be/craft(13): yii\base\Application->run()

Craft CMS version

5.x, currently latest 5.5.7

PHP version

8.3

Operating system and version

Staging: Debian 12 - dev: macOS 15.2

Database type and version

Staging: MariaDB 10.6 - dev MariaDB: 11.6

Image driver and version

No response

Installed plugins and versions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions