Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x]: craft\models\EntryDraft doesn’t exist or doesn’t extend/implement craft\base\ElementInterface #11816

Closed
jerome2710 opened this issue Aug 23, 2022 · 3 comments

Comments

@jerome2710
Copy link

What happened?

Description

After upgrading to Craft 4, some entries in multiple client projects throw a BadRequestHttpException when editing the entry through the CP:

2022-08-23 09:44:35 [web.ERROR] [yii\web\HttpException:400] craft\models\EntryDraft doesn’t exist or doesn’t extend/implement craft\base\ElementInterface

{
	"trace":[
		"#0 /var/www/.../vendor/craftcms/cms/src/controllers/ElementsController.php(1492): craft\\controllers\\ElementsController->_validateElementType('craft\\\\models\\\\En...')",
		"#1 /var/www/.../vendor/craftcms/cms/src/controllers/ElementsController.php(242): craft\\controllers\\ElementsController->_element(2842, NULL, true, false)",
		"#2 [internal function]: craft\\controllers\\ElementsController->actionEdit(NULL, 2842)",
		"#3 /var/www/.../vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)",
		"#4 /var/www/.../vendor/yiisoft/yii2/base/Controller.php(178): yii\\base\\InlineAction->runWithParams(Array)",
		"#5 /var/www/.../vendor/yiisoft/yii2/base/Module.php(552): yii\\base\\Controller->runAction('edit', Array)",
		"#6 /var/www/.../vendor/craftcms/cms/src/web/Application.php(301): yii\\base\\Module->runAction('elements/edit', Array)",
		"#7 /var/www/.../vendor/yiisoft/yii2/web/Application.php(103): craft\\web\\Application->runAction('elements/edit', Array)",
		"#8 /var/www/.../vendor/craftcms/cms/src/web/Application.php(286): yii\\web\\Application->handleRequest(Object(craft\\web\\Request))",
		"#9 /var/www/.../vendor/yiisoft/yii2/base/Application.php(384): craft\\web\\Application->handleRequest(Object(craft\\web\\Request))",
		"#10 /var/www/.../public/index.php(12): yii\\base\\Application->run()",
		"#11 {main}"
	],
	"memory":2859336,
	"exception":"[object] (yii\\web\\BadRequestHttpException(code: 0): craft\\models\\EntryDraft doesn’t exist or doesn’t extend/implement craft\\base\\ElementInterface at /var/www/.../vendor/craftcms/cms/src/controllers/ElementsController.php:1580)"
}

Craft CMS version

4.2.1.1

PHP version

8.1.2

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@brandonkelly
Copy link
Member

We have seen this once or twice in support – there are elements in the elements table where type is set to craft\models\EntryDraft rather than craft\elements\Entry. It’s not really clear how it happens though.

You can resolve by executing the following SQL query:

UPDATE elements SET type = 'craft\elements\Entry'
WHERE type = 'craft\models\EntryDraft'

@jerome2710
Copy link
Author

Thank you for your reply @brandonkelly, this does indeed solve the error. For others, please note you need to escape \ and the tables are usually prefixed with craft_, resulting in:

UPDATE craft_elements SET type = 'craft\\elements\\Entry' 
WHERE type = 'craft\\models\\EntryDraft'

@darylknight
Copy link

Thanks for the solution Brandon!

Jerome is right about needing to escpape the \ characters. Although for anyone else who comes here - tables are generally only prefixed with craft_ if it used to be a Craft CMS 2 website - mine was just called elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants