verbb / super-table

Super-charge your Craft workflow using Super Table.
MIT License
317 stars 47 forks source link

Deleting Supertable field from within a MatrixBlock causes Database Exception #443

Closed RedLucas closed 4 months ago

RedLucas commented 2 years ago

Description I've been able to produce this issue consistently. It seems to be that after attempting to delete a super table field that is within a Matrix field, on the AFTER_DELETE_ELEMENT event, it is running a SELECT query to get the elements to delete. The fields it is trying to get content from are content fields that do not exist, but other fields (I'll attach the query below).

Steps to reproduce

  1. Create a matrix block field.
  2. Add a block type to the matrix block field and add a super table field to it.
  3. Add Matrix block field to an entry type and fill in said fields with content.
  4. Delete Super table block type from within field settings for Matrix block field.
  5. Should land on error.

Additional info

Additional context

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'content.field_pageSection_aBTest' in 'field list'
The SQL being executed was: SELECT `elements`.`id`, `elements`.`fieldLayoutId`, `elements`.`uid`, `elements`.`enabled`, `elements`.`archived`, `elements`.`dateCreated`, `elements`.`dateUpdated`, `elements_sites`.`id` AS `siteSettingsId`, `elements_sites`.`slug`, `elements_sites`.`siteId`, `elements_sites`.`uri`, `elements_sites`.`enabled` AS `enabledForSite`, `elements`.`canonicalId`, `elements`.`dateLastMerged`, `entries`.`sectionId`, `entries`.`typeId`, `entries`.`authorId`, `entries`.`postDate`, `entries`.`expiryDate`, `content`.`id` AS `contentId`, `content`.`title`, `content`.`field_pageSection_aBTest`, `content`.`field_pageSection_allowBlockManipulation`, `content`.`field_pageSection_altText`, `content`.`field_pageSection_billingDisplay`, `content`.`field_pageSection_body`, `content`.`field_pageSection_bufferShareText`, `content`.`field_pageSection_categoryTeamMembersColor`, `content`.`field_pageSection_chargeForBundle`, `content`.`field_pageSection_childNavType`, `content`.`field_pageSection_companyName`, `content`.`field_pageSection_companyUrl`, `content`.`field_pageSection_courseCtaText`, `content`.`field_pageSection_courseTopics`, `content`.`field_pageSection_requirelogin`, `content`.`field_pageSection_seoSettings`, `content`.`field_pageSection_url_`, `content`.`field_pageSection_userGroup`, `content`.`field_pageSection_videoDescription`, `content`.`field_pageSection_videoDownloadUrl`, `content`.`field_pageSection_videoId`, `content`.`field_pageSection_videoIdType`, `content`.`field_pageSection_videoType`, `elements`.`revisionId`, `revisions`.`creatorId` AS `revisionCreatorId`, `revisions`.`num` AS `revisionNum`, `revisions`.`notes` AS `revisionNotes`
FROM (SELECT `elements`.`id` AS `elementsId`, `elements_sites`.`id` AS `elementsSitesId`, `content`.`id` AS `contentId`
FROM `craft_elements` `elements`
INNER JOIN `craft_entries` `entries` ON `entries`.`id` = `elements`.`id`
INNER JOIN `craft_elements_sites` `elements_sites` ON `elements_sites`.`elementId` = `elements`.`id`
INNER JOIN `craft_content` `content` ON `content`.`elementId` = `elements`.`id`
INNER JOIN `craft_revisions` `revisions` ON `revisions`.`id` = `elements`.`revisionId`
WHERE (`elements`.`id`=1076012) AND (`elements`.`archived`=FALSE) AND (`elements`.`dateDeleted` IS NULL) AND (`elements`.`draftId` IS NULL) AND (`elements`.`revisionId`=69399)
ORDER BY `num` DESC
LIMIT 1) `subquery`
INNER JOIN `craft_entries` `entries` ON `entries`.`id` = `subquery`.`elementsId`
INNER JOIN `craft_elements` `elements` ON `elements`.`id` = `subquery`.`elementsId`
INNER JOIN `craft_elements_sites` `elements_sites` ON `elements_sites`.`id` = `subquery`.`elementsSitesId`
INNER JOIN `craft_content` `content` ON `content`.`id` = `subquery`.`contentId`
INNER JOIN `craft_revisions` `revisions` ON `revisions`.`id` = `elements`.`revisionId`
ORDER BY `num` DESC`

In the above case, pageSection is the handle of the block type, not the superTable field (which was named jobPosting). THe super table field that was deleted is not listed.

There's something off about what's it's trying to do here.

martyspain commented 2 years ago

I had a similar problem. Deleting any Super Table field from within a Matrix field would throw a database exception, with the 'Unknown column' error showing a column that doesn't exist. The stack trace showed that the exception was being thrown from the Craft Scout plugin rather than SuperTable, though. I disabled Scout temporarily and tried deleting again and everything worked, so the error may not be with SuperTable if you're using it alongside Scout.

RedLucas commented 2 years ago

I had a similar problem. Deleting any Super Table field from within a Matrix field would throw a database exception, with the 'Unknown column' error showing a column that doesn't exist. The stack trace showed that the exception was being thrown from the Craft Scout plugin rather than SuperTable, though. I disabled Scout temporarily and tried deleting again and everything worked, so the error may not be with SuperTable if you're using it alongside Scout.

Hm yeah, that's interesting. I don't have Scout installed so it's not specifically that. I've been more thinking that it's related to my recent update to 3.7. Was having performance problems but the 2.7 super table update seemed to help... but I'm wondering if there may still be bugs.

I'll try to gather more information though. Was hoping others would begin seeing this over time as well.

strandofgenius commented 2 years ago

I'm currently having this same error on Craft 4 and had been running version 4.0.0_beta6. Now I am unable to edit or save new entries that had a block with the matrix block -> supertable -> matrix block setup

shoored commented 1 year ago

On Craft 3, in Field settings, when deleting a Supertable field inside a Matrix block I get the following error on Postgres:

SQLSTATE[25P02]: In failed sql transaction: 7 ERROR: current transaction is aborted, commands ignored until end of transaction block
The SQL being executed was: UPDATE "elements" SET "dateDeleted"='2023-02-08 10:13:19' WHERE "id"=5941788.
--

in /var/www/html/vendor/verbb/super-table/src/services/SuperTableService.php at line 446
craft\services\Elements::deleteElement(verbb\supertable\elements\SuperTableBlockElement)

I've tried to do it in steps. Delete the SuperTable field rows one by one. Deleting the first row and then saving the Matrix field works. But when I try to save the Matrix field when the SuperTable field has no rows or the SuperTable field has been removed, the error occurs.

Craft 3.7.65 SuperTable 2.7.4 Postgress 11

bymayo commented 1 year ago

@martyspain Your correct, disabling Scout plugin seems to allow you to delete the Super Table field, from within a Matrix. Not sure who's issue this is, whether it's with Super Table or Scout?!

shoored commented 1 year ago

Hey, I'm having this same kinda issue again. While deleting a Matrix block which contains a SuperTable field I receive this error:

It seems like there's an issue with SuperTable but I'm not completely positive.

This is on

2023-06-15 16:00:28 [-][1][668f13d66d670c07ff467d7dd5ba849e][error][yii\db\Exception] PDOException: SQLSTATE[25P02]: In failed sql transaction: 7 ERROR:  current transaction is aborted, commands ignored until end of transaction block in /var/www/html/vendor/yiisoft/yii2/db/Command.php:1302
Stack trace:
#0 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1302): PDOStatement->execute()
#1 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1102): yii\db\Command->internalExecute('UPDATE "element...')
#2 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(1736): yii\db\Command->execute()
#3 /var/www/html/vendor/verbb/super-table/src/services/SuperTableService.php(446): craft\services\Elements->deleteElement(Object(verbb\supertable\elements\SuperTableBlockElement))
#4 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(1199): verbb\supertable\services\SuperTableService->handleDeletedBlockType(Object(craft\events\ConfigEvent))
#5 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#6 /var/www/html/vendor/yiisoft/yii2/base/Component.php(633): call_user_func(Array, Object(craft\events\ConfigEvent))
#7 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(765): yii\base\Component->trigger('removeItem', Object(craft\events\ConfigEvent))
#8 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(544): craft\services\ProjectConfig->_processConfigChangesInternal('superTableBlock...', true, 'Delete super ta...')
#9 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(560): craft\services\ProjectConfig->set('superTableBlock...', NULL, 'Delete super ta...')
#10 /var/www/html/vendor/verbb/super-table/src/services/SuperTableService.php(405): craft\services\ProjectConfig->remove('superTableBlock...', 'Delete super ta...')
#11 /var/www/html/vendor/verbb/super-table/src/services/SuperTableService.php(662): verbb\supertable\services\SuperTableService->deleteBlockType(Object(verbb\supertable\models\SuperTableBlockTypeModel))
#12 /var/www/html/vendor/verbb/super-table/src/fields/SuperTableField.php(1059): verbb\supertable\services\SuperTableService->deleteSuperTableField(Object(verbb\supertable\fields\SuperTableField))
#13 /var/www/html/vendor/craftcms/cms/src/services/Fields.php(1016): verbb\supertable\fields\SuperTableField->beforeApplyDelete()
#14 /var/www/html/vendor/craftcms/cms/src/services/Fields.php(967): craft\services\Fields->applyFieldDelete('6f2dee5f-f87f-4...')
#15 /var/www/html/vendor/craftcms/cms/src/services/Matrix.php(445): craft\services\Fields->deleteField(Object(verbb\supertable\fields\SuperTableField))
#16 /var/www/html/vendor/craftcms/cms/src/base/ApplicationTrait.php(1706): craft\services\Matrix->handleDeletedBlockType(Object(craft\events\ConfigEvent))
#17 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(1199): craft\web\Application->craft\base\{closure}(Object(craft\events\ConfigEvent))
#18 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#19 /var/www/html/vendor/yiisoft/yii2/base/Component.php(633): call_user_func(Array, Object(craft\events\ConfigEvent))
#20 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(765): yii\base\Component->trigger('removeItem', Object(craft\events\ConfigEvent))
#21 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(544): craft\services\ProjectConfig->_processConfigChangesInternal('matrixBlockType...', true, 'Delete matrix b...')
#22 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(560): craft\services\ProjectConfig->set('matrixBlockType...', NULL, 'Delete matrix b...')
#23 /var/www/html/vendor/craftcms/cms/src/services/Matrix.php(380): craft\services\ProjectConfig->remove('matrixBlockType...', 'Delete matrix b...')
#24 /var/www/html/vendor/craftcms/cms/src/services/Matrix.php(581): craft\services\Matrix->deleteBlockType(Object(craft\models\MatrixBlockType))
#25 /var/www/html/vendor/craftcms/cms/src/fields/Matrix.php(1014): craft\services\Matrix->saveSettings(Object(craft\fields\Matrix), false)
#26 /var/www/html/vendor/craftcms/cms/src/services/Fields.php(1923): craft\fields\Matrix->afterSave(false)
#27 /var/www/html/vendor/craftcms/cms/src/services/Fields.php(924): craft\services\Fields->applyFieldSave('8c3cfc26-1749-4...', Array, 'global')
#28 /var/www/html/vendor/craftcms/cms/src/base/ApplicationTrait.php(1706): craft\services\Fields->handleChangedField(Object(craft\events\ConfigEvent))
#29 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(1199): craft\web\Application->craft\base\{closure}(Object(craft\events\ConfigEvent))
#30 [internal function]: craft\services\ProjectConfig->handleChangeEvent(Object(craft\events\ConfigEvent))
#31 /var/www/html/vendor/yiisoft/yii2/base/Component.php(633): call_user_func(Array, Object(craft\events\ConfigEvent))
#32 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(771): yii\base\Component->trigger('updateItem', Object(craft\events\ConfigEvent))
#33 /var/www/html/vendor/craftcms/cms/src/services/ProjectConfig.php(544): craft\services\ProjectConfig->_processConfigChangesInternal('fields.8c3cfc26...', true, 'Save field \xE2\x80\x9Cc...')
#34 /var/www/html/vendor/craftcms/cms/src/services/Fields.php(861): craft\services\ProjectConfig->set('fields.8c3cfc26...', Array, 'Save field \xE2\x80\x9Cc...')
#35 /var/www/html/vendor/craftcms/cms/src/controllers/FieldsController.php(335): craft\services\Fields->saveField(Object(craft\fields\Matrix))
#36 [internal function]: craft\controllers\FieldsController->actionSaveField()
#37 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#38 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#39 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('save-field', Array)
#40 /var/www/html/vendor/craftcms/cms/src/web/Application.php(295): yii\base\Module->runAction('fields/save-fie...', Array)
#41 /var/www/html/vendor/craftcms/cms/src/web/Application.php(608): craft\web\Application->runAction('fields/save-fie...', Array)
#42 /var/www/html/vendor/craftcms/cms/src/web/Application.php(274): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#43 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#44 /var/www/html/html/index.php(32): yii\base\Application->run()
#45 {main}