craftcms / cms

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

[3.7.40]: Unable to delete global set #11100

Closed WebtradersDev closed 2 years ago

WebtradersDev commented 2 years ago

What happened?

Description

When I try to delete a global set the global sets table gets grayed out without any errors. When having a look at my network requests I see the following response:

{"error":"Invalid field layout ID: 63","exception":"yii\\base\\InvalidConfigException","file":"/var/www/vendor/craftcms/cms/src/behaviors/FieldLayoutBehavior.php","line":125,"trace":[{"file":"/var/www/vendor/craftcms/cms/src/elements/GlobalSet.php","line":227,"function":"getFieldLayout","class":"craft\\behaviors\\FieldLayoutBehavior","type":"->"},{"file":"/var/www/vendor/craftcms/cms/src/base/Element.php","line":4354,"function":"getFieldLayout","class":"craft\\elements\\GlobalSet","type":"->"},{"file":"/var/www/vendor/craftcms/cms/src/base/Element.php","line":4177,"function":"fieldLayoutFields","class":"craft\\base\\Element","type":"->"},{"file":"/var/www/vendor/craftcms/cms/src/elements/GlobalSet.php","line":259,"function":"beforeDelete","class":"craft\\base\\Element","type":"->"},{"file":"/var/www/vendor/craftcms/cms/src/services/Elements.php","line":1677,"function":"beforeDelete","class":"craft\\elements\\GlobalSet","type":"->"},{"file":"/var/www/vendor/craftcms/cms/src/services/Elements.php","line":1655,"function":"deleteElement","class":"craft\\services\\Elements","type":"->"},{"file":"/var/www/vendor/craftcms/cms/src/services/Globals.php","line":500,"function":"deleteElementById","class":"craft\\services\\Elements","type":"->"},{"file":"/var/www/vendor/craftcms/cms/src/base/ApplicationTrait.php","line":1681,"function":"handleDeletedGlobalSet","class":"craft\\services\\Globals","type":"->"},{"file":"/var/www/vendor/craftcms/cms/src/services/ProjectConfig.php","line":1199,"function":"craft\\base\\{closure}","class":"craft\\web\\Application","type":"->"},{"function":"handleChangeEvent","class":"craft\\services\\ProjectConfig","type":"->"},{"file":"/var/www/vendor/yiisoft/yii2/base/Component.php","line":633,"function":"call_user_func"},{"file":"/var/www/vendor/craftcms/cms/src/services/ProjectConfig.php","line":765,"function":"trigger","class":"yii\\base\\Component","type":"->"},{"file":"/var/www/vendor/craftcms/cms/src/services/ProjectConfig.php","line":544,"function":"_processConfigChangesInternal","class":"craft\\services\\ProjectConfig","type":"->"},{"file":"/var/www/vendor/craftcms/cms/src/services/ProjectConfig.php","line":560,"function":"set","class":"craft\\services\\ProjectConfig","type":"->"},{"file":"/var/www/vendor/craftcms/cms/src/services/Globals.php","line":469,"function":"remove","class":"craft\\services\\ProjectConfig","type":"->"},{"file":"/var/www/vendor/craftcms/cms/src/services/Globals.php","line":457,"function":"deleteSet","class":"craft\\services\\Globals","type":"->"},{"file":"/var/www/vendor/craftcms/cms/src/controllers/GlobalsController.php","line":127,"function":"deleteGlobalSetById","class":"craft\\services\\Globals","type":"->"},{"function":"actionDeleteSet","class":"craft\\controllers\\GlobalsController","type":"->"},{"file":"/var/www/vendor/yiisoft/yii2/base/InlineAction.php","line":57,"function":"call_user_func_array"},{"file":"/var/www/vendor/yiisoft/yii2/base/Controller.php","line":178,"function":"runWithParams","class":"yii\\base\\InlineAction","type":"->"},{"file":"/var/www/vendor/yiisoft/yii2/base/Module.php","line":552,"function":"runAction","class":"yii\\base\\Controller","type":"->"},{"file":"/var/www/vendor/craftcms/cms/src/web/Application.php","line":293,"function":"runAction","class":"yii\\base\\Module","type":"->"},{"file":"/var/www/vendor/craftcms/cms/src/web/Application.php","line":602,"function":"runAction","class":"craft\\web\\Application","type":"->"},{"file":"/var/www/vendor/craftcms/cms/src/web/Application.php","line":272,"function":"_processActionRequest","class":"craft\\web\\Application","type":"->"},{"file":"/var/www/vendor/yiisoft/yii2/base/Application.php","line":384,"function":"handleRequest","class":"craft\\web\\Application","type":"->"},{"file":"/var/www/public/index.php","line":12,"function":"run","class":"yii\\base\\Application","type":"->"}]}

I also tried deleting the global set by removing it from the project config and reapplying it, however that also results in an error:

Applying changes from your project config files ...
- removing globalSets.d62b5cc5-095b-4a7d-bbe6-7bfd930c1b03.fieldLayouts.0277e198-7dce-46f1-9e40-219b9f273012.tabs.0.elements.0 ... 
  - removing globalSets.d62b5cc5-095b-4a7d-bbe6-7bfd930c1b03 ... 
error: Invalid field layout ID: 63

Steps to reproduce

  1. Create a global set
  2. Try to delete the global set

Expected behavior

The global set to be deleted.

Actual behavior

See description

Craft CMS version

3.7.40.1

PHP version

8.0.17

Operating system and version

Linux 5.10.104-linuxkit

Database type and version

MySQL 8.0.28

Image driver and version

Imagick 3.7.0 (ImageMagick 7.1.0-16)

Installed plugins and versions

Redactor 2.10.8 Retour 3.1.71 SEOmatic 3.4.30 Typed link field 1.0.25 Vite 1.0.24 Wheel Form 2.7.2

Wiejeben commented 2 years ago

Posted the issue from our work GitHub. I have checked the fieldlayouts table and ID 63 does exist and is of type craft\elements\GlobalSet.

Did some further investigating. When the getLayoutById(...)returns null I check the global set via an where instead of an andWhere:

$this->_createLayoutQuery()
                ->select('*')
                ->where(['id' => $layoutId])
                ->one()

This returns the global set with dateDeleted. However if I were to guess because of the subsequent exception the database transaction is undone, undoing the softdelete.

brandonkelly commented 2 years ago

Thanks for reporting! Just fixed this for the next release.

To get the fix early, change your craftcms/cms requirement in composer.json to "dev-release/3.7.41 as 3.7.40" and run composer update.

brandonkelly commented 2 years ago

Craft 3.7.41 is out now with that fix.