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

Exception after "Approve and publish" submit #161

Closed
birgerstoeckelmann opened this issue Aug 23, 2022 · 2 comments
Closed

Exception after "Approve and publish" submit #161

birgerstoeckelmann opened this issue Aug 23, 2022 · 2 comments

Comments

@birgerstoeckelmann
Copy link

Describe the bug

After submit via "Approve and publish" an exception is thrown with "Integrity constraint violation" - see stack trace below - but the entry is saved and updated.

The workflow submission is listed as a deleted item.

Steps to reproduce

  1. login as editor (can only create drafts)
  2. create draft from existing entry (e.g. from single section type)
  3. submit draft for approval with "Save draft and submit for review" button
  4. login as chief editor
  5. try to approve and publish item with "Approve and publish" button

Craft CMS version

4.2.1.1

Plugin version

dev-craft-4 as 2.0.0-beta.5

Multi-site?

Yes

Additional context

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (db.workflow_submissions, CONSTRAINT fk_diqywvmwbslvmuhwmydkadgiokqfxjoigxty FOREIGN KEY (ownerId) REFERENCES elements (id) ON DELETE SET NULL) 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 `workflo...')
#2 /var/www/html/vendor/yiisoft/yii2/db/ActiveRecord.php(336): yii\db\Command->execute()
#3 /var/www/html/vendor/yiisoft/yii2/db/BaseActiveRecord.php(808): yii\db\ActiveRecord::updateAll(Array, Array)
#4 /var/www/html/vendor/yiisoft/yii2/db/ActiveRecord.php(680): yii\db\BaseActiveRecord->updateInternal(NULL)
#5 /var/www/html/vendor/yiisoft/yii2/db/BaseActiveRecord.php(679): yii\db\ActiveRecord->update(false, NULL)
#6 /var/www/html/vendor/verbb/workflow/src/elements/Submission.php(458): yii\db\BaseActiveRecord->save(false)
#7 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(2730): verbb\workflow\elements\Submission->afterSave(false)
#8 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(795): craft\services\Elements->_saveElementInternal(Object(verbb\workflow\elements\Submission), true, false, true)
#9 /var/www/html/vendor/verbb/workflow/src/services/Submissions.php(297): craft\services\Elements->saveElement(Object(verbb\workflow\elements\Submission))
#10 /var/www/html/vendor/verbb/workflow/src/services/Service.php(193): verbb\workflow\services\Submissions->approveSubmission(Object(craft\elements\Entry))
#11 [internal function]: verbb\workflow\services\Service->onAfterApplyDraft(Object(craft\events\DraftEvent))
#12 /var/www/html/vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Array, Object(craft\events\DraftEvent))
#13 /var/www/html/vendor/yiisoft/yii2/base/Component.php(642): yii\base\Event::trigger('craft\services\...', 'afterApplyDraft', Object(craft\events\DraftEvent))
#14 /var/www/html/vendor/craftcms/cms/src/services/Drafts.php(340): yii\base\Component->trigger('afterApplyDraft', Object(craft\events\DraftEvent))
#15 /var/www/html/vendor/craftcms/cms/src/controllers/ElementsController.php(1275): craft\services\Drafts->applyDraft(Object(craft\elements\Entry))
#16 [internal function]: craft\controllers\ElementsController->actionApplyDraft()
#17 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#18 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#19 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('apply-draft', Array)
#20 /var/www/html/vendor/craftcms/cms/src/web/Application.php(301): yii\base\Module->runAction('elements/apply-...', Array)
#21 /var/www/html/vendor/verbb/workflow/src/controllers/SubmissionsController.php(106): craft\web\Application->runAction('elements/apply-...')
#22 [internal function]: verbb\workflow\controllers\SubmissionsController->actionPublishEntry()
#23 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#24 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#25 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('publish-entry', Array)
#26 /var/www/html/vendor/craftcms/cms/src/web/Application.php(301): yii\base\Module->runAction('workflow/submis...', Array)
#27 /var/www/html/vendor/craftcms/cms/src/web/Application.php(625): craft\web\Application->runAction('workflow/submis...', Array)
#28 /var/www/html/vendor/craftcms/cms/src/web/Application.php(280): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#29 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#30 /var/www/html/web/index.php(12): yii\base\Application->run()
#31 {main}

Next yii\db\IntegrityException: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (db.workflow_submissions, CONSTRAINT fk_diqywvmwbslvmuhwmydkadgiokqfxjoigxty FOREIGN KEY (ownerId) REFERENCES elements (id) ON DELETE SET NULL)
The SQL being executed was: UPDATE workflow_submissions SET ownerId=3046, publisherId=667, status='approved', publisherNotes='Yes!', dateApproved='2022-08-23 13:54:03', dateUpdated='2022-08-23 13:54:03' WHERE id=3048 in /var/www/html/vendor/yiisoft/yii2/db/Schema.php:676
Stack trace:
#0 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1307): yii\db\Schema->convertException(Object(PDOException), 'UPDATE workflo...') #1 /var/www/html/vendor/yiisoft/yii2/db/Command.php(1102): yii\db\Command->internalExecute('UPDATE workflo...')
#2 /var/www/html/vendor/yiisoft/yii2/db/ActiveRecord.php(336): yii\db\Command->execute()
#3 /var/www/html/vendor/yiisoft/yii2/db/BaseActiveRecord.php(808): yii\db\ActiveRecord::updateAll(Array, Array)
#4 /var/www/html/vendor/yiisoft/yii2/db/ActiveRecord.php(680): yii\db\BaseActiveRecord->updateInternal(NULL)
#5 /var/www/html/vendor/yiisoft/yii2/db/BaseActiveRecord.php(679): yii\db\ActiveRecord->update(false, NULL)
#6 /var/www/html/vendor/verbb/workflow/src/elements/Submission.php(458): yii\db\BaseActiveRecord->save(false)
#7 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(2730): verbb\workflow\elements\Submission->afterSave(false)
#8 /var/www/html/vendor/craftcms/cms/src/services/Elements.php(795): craft\services\Elements->_saveElementInternal(Object(verbb\workflow\elements\Submission), true, false, true)
#9 /var/www/html/vendor/verbb/workflow/src/services/Submissions.php(297): craft\services\Elements->saveElement(Object(verbb\workflow\elements\Submission))
#10 /var/www/html/vendor/verbb/workflow/src/services/Service.php(193): verbb\workflow\services\Submissions->approveSubmission(Object(craft\elements\Entry))
#11 [internal function]: verbb\workflow\services\Service->onAfterApplyDraft(Object(craft\events\DraftEvent))
#12 /var/www/html/vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Array, Object(craft\events\DraftEvent))
#13 /var/www/html/vendor/yiisoft/yii2/base/Component.php(642): yii\base\Event::trigger('craft\services\...', 'afterApplyDraft', Object(craft\events\DraftEvent))
#14 /var/www/html/vendor/craftcms/cms/src/services/Drafts.php(340): yii\base\Component->trigger('afterApplyDraft', Object(craft\events\DraftEvent))
#15 /var/www/html/vendor/craftcms/cms/src/controllers/ElementsController.php(1275): craft\services\Drafts->applyDraft(Object(craft\elements\Entry))
#16 [internal function]: craft\controllers\ElementsController->actionApplyDraft()
#17 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#18 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#19 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('apply-draft', Array)
#20 /var/www/html/vendor/craftcms/cms/src/web/Application.php(301): yii\base\Module->runAction('elements/apply-...', Array)
#21 /var/www/html/vendor/verbb/workflow/src/controllers/SubmissionsController.php(106): craft\web\Application->runAction('elements/apply-...')
#22 [internal function]: verbb\workflow\controllers\SubmissionsController->actionPublishEntry()
#23 /var/www/html/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
#24 /var/www/html/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
#25 /var/www/html/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('publish-entry', Array)
#26 /var/www/html/vendor/craftcms/cms/src/web/Application.php(301): yii\base\Module->runAction('workflow/submis...', Array)
#27 /var/www/html/vendor/craftcms/cms/src/web/Application.php(625): craft\web\Application->runAction('workflow/submis...', Array)
#28 /var/www/html/vendor/craftcms/cms/src/web/Application.php(280): craft\web\Application->_processActionRequest(Object(craft\web\Request))
#29 /var/www/html/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
#30 /var/www/html/web/index.php(12): yii\base\Application->run()
#31 {main}
Additional Information:
Array
(
[0] => 23000
[1] => 1452
[2] => Cannot add or update a child row: a foreign key constraint fails (db.workflow_submissions, CONSTRAINT fk_diqywvmwbslvmuhwmydkadgiokqfxjoigxty FOREIGN KEY (ownerId) REFERENCES elements (id) ON DELETE SET NULL)
)

@engram-design
Copy link
Member

Yeah this is a tricky one. It's because the entry element (the draft) that Workflow is working with actually gets deleted when it's approved, hence when trying to save the Workflow Submission that is linked to that now-deleted entry element causes this error.

Should be fixed in 2.0.0-beta.6

@birgerstoeckelmann
Copy link
Author

Yes, it's working now! Thank you!

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

No branches or pull requests

2 participants