craftcms / cms

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

[5.0.0]: Invalid owner ID errors #14749

Closed rinusvandam closed 7 months ago

rinusvandam commented 7 months ago

What happened?

Description

I've updated a Craft site to version 5. I'm getting “Invalid owner ID” errors.

Steps to reproduce

It appears to happen at random moments. Can't find a way to reproduce it. I've seen more issues related to this.

Stack trace

yii\base\InvalidConfigException: Invalid owner ID: 182571 in /var/www/html/vendor/craftcms/cms/src/base/NestedElementTrait.php:148
#0 /var/www/html/vendor/craftcms/cms/src/base/NestedElementTrait.php(193): craft\elements\Entry->getPrimaryOwner()
#1 /var/www/html/vendor/craftcms/cms/src/base/NestedElementTrait.php(225): craft\elements\Entry->getOwner()
#2 /var/www/html/vendor/craftcms/cms/src/base/Element.php(3243): craft\elements\Entry->getField()
#3 /var/www/html/vendor/craftcms/cms/src/elements/Entry.php(1655): craft\base\Element->canView(Object(craft\elements\User))
#4 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(4139): craft\elements\Entry->canView(Object(craft\elements\User))
#5 /var/www/html/vendor/craftcms/cms/src/helpers/Cp.php(663): craft\services\Elements->canView(Object(craft\elements\Entry), Object(craft\elements\User))
#6 /var/www/html/vendor/craftcms/cms/src/helpers/Cp.php(464): craft\helpers\Cp::baseElementAttributes(Object(craft\elements\Entry), Array)
#7 /var/www/html/vendor/craftcms/cms/src/widgets/MyDrafts.php(106): craft\helpers\Cp::elementChipHtml(Object(craft\elements\Entry))
#8 /var/www/html/vendor/craftcms/cms/src/controllers/DashboardController.php(466): craft\widgets\MyDrafts->getBodyHtml()
#9 /var/www/html/vendor/craftcms/cms/src/controllers/DashboardController.php(104): craft\controllers\DashboardController->_getWidgetInfo(Object(craft\widgets\MyDrafts))
#10 [internal function]: craft\controllers\DashboardController->actionIndex()
#11 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#12 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#13 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('index', Array)
#14 /var/www/html/vendor/craftcms/cms/src/web/Application.php(349): yii\base\Module->runAction('dashboard/index', Array)
#15 /var/www/html/vendor/yiisoft/yii2/web/Application.php(103): craft\web\Application->runAction('dashboard/index', Array)
#16 /var/www/html/vendor/craftcms/cms/src/web/Application.php(317): yii\web\Application->handleRequest(Object(craft\web\Request))
#17 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#18 /var/www/html/public_html/index.php(12): yii\base\Application->run()
#19 {main}

Craft CMS version

Craft Pro 5.0.0

PHP version

8.2.15

Operating system and version

MacOS 14.4 (23E214)

Database type and version

MySQL 8.0.33

Image driver and version

Imagick 3.7.0 (ImageMagick 6.9.11-60)

Installed plugins and versions

rinusvandam commented 7 months ago

I have an update on this. The error message always appeared when I tried to open the CP dashboard.

The only reason for this I could find is that my dashboard shows recent drafts. One of them might have been corrupted. I'm not sure why. But other issues are related to corrupted matrix blocks.

I tried running the craft gc command. And voilà, the error is gone.

brandonkelly commented 7 months ago

Is this a multi-site install, and do you have a section which allows entries to choose which sites they belong to? If so this may be the same issue as #13948, which was fixed in 4.7.0 and can be fixed retroactively by running craft gc as you did.

rinusvandam commented 7 months ago

Is this a multi-site install, and do you have a section which allows entries to choose which sites they belong to? If so this may be the same issue as #13948, which was fixed in 4.7.0 and can be fixed retroactively by running craft gc as you did.

It's a multi-site install. But it doesn't have sections that allow entries to choose which sites they belong to.

diegocosta-dev commented 5 months ago

CraftCMS Version: 5.1.7 Error: Invalid owner ID

I am encountering this error when enabling the Drafts widget on the CraftCMS dashboard.

brandonkelly commented 5 months ago

@diegocosta-dev I’m not able to reproduce. Have you tried running craft gc as previously suggested? If that doesn’t help, can you send your database backup and Composer files into support@craftcms.com?

diegocosta-dev commented 5 months ago

Have you tried running craft gc as previously suggested?

@brandonkelly Thank you for the suggestion! I have resolved the issue by running the craft gc command as you suggested. Everything is working perfectly now.

brandonkelly commented 5 months ago

I ended up running into this myself, and realized it’s still a bug when there were nested Matrix entries that were created and then discarded. Fixed for the next release!

diegocosta-dev commented 5 months ago

I ended up running into this myself, and realized it’s still a bug when there were nested Matrix entries that were created and then discarded. Fixed for the next release!

That's great, thanks! 😊

brandonkelly commented 5 months ago

Craft 5.1.10 is out now with that fix.

plcdnl commented 4 months ago

Hi, sorry for the disturb.

I'm continuing to have this error also if i try to use craft gc

image
brandonkelly commented 4 months ago

@plcdnl Can you specify your Craft version, and post the complete stack trace?

plcdnl commented 4 months ago

Hi @brandonkelly thank you in advance and sorry for the disturb.

Craft version is Craft Pro 5.2.4.1 and this is the stack trace:

Running garbage collection ...
    > purging unsaved drafts that have gone stale ... Exception 'yii\base\InvalidConfigException' with message 'Invalid owner ID: 11184'

in /var/www/html/vendor/craftcms/cms/src/base/NestedElementTrait.php:158

Stack trace:
#0 /var/www/html/vendor/craftcms/cms/src/base/NestedElementTrait.php(203): craft\elements\Entry->getPrimaryOwner()
#1 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(814): craft\elements\Entry->getOwner()
#2 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(2297): craft\services\Elements->invalidateCachesForElement(Object(craft\elements\Entry))
#3 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(1170): craft\services\Elements->craft\services\{closure}()
#4 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(2279): craft\services\Elements->ensureBulkOp(Object(Closure))
#5 /var/www/html/vendor/craftcms/cms/src/services/Drafts.php(455): craft\services\Elements->deleteElement(Object(craft\elements\Entry), true)
#6 /var/www/html/vendor/craftcms/cms/src/services/Gc.php(362): craft\services\Drafts->purgeUnsavedDrafts()
#7 /var/www/html/vendor/craftcms/cms/src/services/Gc.php(101): craft\services\Gc->_purgeUnsavedDrafts()
#8 /var/www/html/vendor/craftcms/cms/src/console/controllers/GcController.php(56): craft\services\Gc->run(true)
#9 [internal function]: craft\console\controllers\GcController->actionRun()
#10 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#11 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#12 /var/www/html/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('', Array)
#13 /var/www/html/vendor/craftcms/cms/src/console/ControllerTrait.php(89): yii\console\Controller->runAction('', Array)
#14 /var/www/html/vendor/craftcms/cms/src/console/Controller.php(216): craft\console\Controller->traitRunAction('', Array)
#15 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): craft\console\Controller->runAction('', Array)
#16 /var/www/html/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('gc', Array)
#17 /var/www/html/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('gc', Array)
#18 /var/www/html/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('gc', Array)
#19 /var/www/html/vendor/craftcms/cms/src/console/Application.php(122): yii\console\Application->handleRequest(Object(craft\console\Request))
#20 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
#21 /var/www/html/craft(13): yii\base\Application->run()
#22 {main}
Failed to run craft gc: exit status 1
rinusvandam commented 4 months ago

Hi @brandonkelly thank you in advance and sorry for the disturb.

Craft version is Craft Pro 5.2.4.1 and this is the stack trace:

Running garbage collection ...
    > purging unsaved drafts that have gone stale ... Exception 'yii\base\InvalidConfigException' with message 'Invalid owner ID: 11184'

in /var/www/html/vendor/craftcms/cms/src/base/NestedElementTrait.php:158

Stack trace:
#0 /var/www/html/vendor/craftcms/cms/src/base/NestedElementTrait.php(203): craft\elements\Entry->getPrimaryOwner()
#1 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(814): craft\elements\Entry->getOwner()
#2 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(2297): craft\services\Elements->invalidateCachesForElement(Object(craft\elements\Entry))
#3 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(1170): craft\services\Elements->craft\services\{closure}()
#4 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(2279): craft\services\Elements->ensureBulkOp(Object(Closure))
#5 /var/www/html/vendor/craftcms/cms/src/services/Drafts.php(455): craft\services\Elements->deleteElement(Object(craft\elements\Entry), true)
#6 /var/www/html/vendor/craftcms/cms/src/services/Gc.php(362): craft\services\Drafts->purgeUnsavedDrafts()
#7 /var/www/html/vendor/craftcms/cms/src/services/Gc.php(101): craft\services\Gc->_purgeUnsavedDrafts()
#8 /var/www/html/vendor/craftcms/cms/src/console/controllers/GcController.php(56): craft\services\Gc->run(true)
#9 [internal function]: craft\console\controllers\GcController->actionRun()
#10 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#11 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#12 /var/www/html/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('', Array)
#13 /var/www/html/vendor/craftcms/cms/src/console/ControllerTrait.php(89): yii\console\Controller->runAction('', Array)
#14 /var/www/html/vendor/craftcms/cms/src/console/Controller.php(216): craft\console\Controller->traitRunAction('', Array)
#15 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): craft\console\Controller->runAction('', Array)
#16 /var/www/html/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('gc', Array)
#17 /var/www/html/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('gc', Array)
#18 /var/www/html/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('gc', Array)
#19 /var/www/html/vendor/craftcms/cms/src/console/Application.php(122): yii\console\Application->handleRequest(Object(craft\console\Request))
#20 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
#21 /var/www/html/craft(13): yii\base\Application->run()
#22 {main}
Failed to run craft gc: exit status 1

What helped in my case was using the --delete-all-trashed option. See: https://craftcms.com/docs/5.x/reference/cli.html#gc-run

plcdnl commented 4 months ago

thank you @rinusvandam. I tried with it but same error 😞

michtio commented 3 months ago

@brandonkelly I see this issue is closed, but running in exact the same situation when running craft gc

➜  go4jobs-site git:(develop) ✗ ddev craft gc
Delete all trashed items? (yes|no) [no]:y
Running garbage collection ...
    > purging unsaved drafts that have gone stale ... Exception 'yii\base\InvalidConfigException' with message 'Invalid owner ID: 3133'

in /var/www/html/cms/vendor/craftcms/cms/src/base/NestedElementTrait.php:158

Stack trace:
#0 /var/www/html/cms/vendor/craftcms/cms/src/base/NestedElementTrait.php(203): craft\elements\Entry->getPrimaryOwner()
#1 /var/www/html/cms/vendor/craftcms/cms/src/services/Elements.php(814): craft\elements\Entry->getOwner()
#2 /var/www/html/cms/vendor/craftcms/cms/src/services/Elements.php(2313): craft\services\Elements->invalidateCachesForElement()
#3 /var/www/html/cms/vendor/craftcms/cms/src/services/Elements.php(1170): craft\services\Elements->craft\services\{closure}()
#4 /var/www/html/cms/vendor/craftcms/cms/src/services/Elements.php(2295): craft\services\Elements->ensureBulkOp()
#5 /var/www/html/cms/vendor/craftcms/cms/src/services/Drafts.php(455): craft\services\Elements->deleteElement()
#6 /var/www/html/cms/vendor/craftcms/cms/src/services/Gc.php(362): craft\services\Drafts->purgeUnsavedDrafts()
#7 /var/www/html/cms/vendor/craftcms/cms/src/services/Gc.php(101): craft\services\Gc->_purgeUnsavedDrafts()
#8 /var/www/html/cms/vendor/craftcms/cms/src/console/controllers/GcController.php(56): craft\services\Gc->run()
#9 [internal function]: craft\console\controllers\GcController->actionRun()
#10 /var/www/html/cms/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#11 /var/www/html/cms/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams()
#12 /var/www/html/cms/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction()
#13 /var/www/html/cms/vendor/craftcms/cms/src/console/ControllerTrait.php(89): yii\console\Controller->runAction()
#14 /var/www/html/cms/vendor/craftcms/cms/src/console/Controller.php(216): craft\console\Controller->traitRunAction()
#15 /var/www/html/cms/vendor/yiisoft/yii2/base/Module.php(552): craft\console\Controller->runAction()
#16 /var/www/html/cms/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction()
#17 /var/www/html/cms/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction()
#18 /var/www/html/cms/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction()
#19 /var/www/html/cms/vendor/craftcms/cms/src/console/Application.php(122): yii\console\Application->handleRequest()
#20 /var/www/html/cms/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest()
#21 /var/www/html/cms/craft(13): yii\base\Application->run()
#22 {main}

also in this case, it's not a multi-site

Craft version is 5.2.8 (I can deliver a DB if necessary)

plcdnl commented 3 months ago

Also for me, not a multi-site

michtio commented 3 months ago

Hi Guys,

In my case, the ddev craft gc command worked, so maybe this could help. The error "Invalid owner ID errors" only occurred when I was on the main dashboard page (https://site.ddev.site/admin/dashboard). I was able to access other backend pages normally, such as https://site.ddev.site/admin/users/all.

So, I created a new administrator account and was able to log into the dashboard without any problems. I believe this issue is related to the widget's user configuration on the dashboard.

Note: This worked for me. It might be different for you.

I think this is unrelated and might be another issue. I don't have any issues personally going around in the CP, creating, editing ... content, everything works as normal. Just the gc/run command throwing errors.

brandonkelly commented 3 months ago

@michtio Can you send your database backup and Composer files into support@craftcms.com?

cornedor commented 2 months ago

I had the same issue, what helped for me was looking up the owner ID in the entries table, and open the entrytypes row linked by typeId. Lookup that entry type in the entry config in the admin, and resave it. For me, it would re-add the title field to the config file.

https://github.com/user-attachments/assets/287e19c2-e755-4e8b-881b-fe4c3c48380d