Steps to reproduce
- Start creating a new node which has a moderation workflow, e.g. node/add/page
- enter some text
- go to preview
- change moderation state, click apply
- go back to editing
- save
- /node/add/page?uuid=f0a2210f-bedd-4268-8456-67b95511a39e
Expected result
Node should be saved
Actual result
The website encountered an unexpected error. Please try again later.</br></br><em class="placeholder">Drupal\Core\Entity\EntityStorageException</em>: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'f0a2210f-bedd-4268-8456-67b95511a39e' for key 'node_field__uuid__value': INSERT INTO {node} (vid, type, uuid, langcode) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array
(
[:db_insert_placeholder_0] =>
[:db_insert_placeholder_1] => page
[:db_insert_placeholder_2] => f0a2210f-bedd-4268-8456-67b95511a39e
[:db_insert_placeholder_3] => en
)
in <em class="placeholder">Drupal\Core\Entity\Sql\SqlContentEntityStorage->save()</em> (line <em class="placeholder">805</em> of <em class="placeholder">core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php</em>). <pre class="backtrace">Drupal\Core\Database\Statement->execute(Array, Array) (Line: 625)
Drupal\Core\Database\Connection->query('INSERT INTO {node} (vid, type, uuid, langcode) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3)', Array, Array) (Line: 87)
Drupal\Core\Database\Driver\mysql\Connection->query('INSERT INTO {node} (vid, type, uuid, langcode) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3)', Array, Array) (Line: 32)
Drupal\Core\Database\Driver\mysql\Insert->execute() (Line: 878)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->doSaveFieldItems(Object) (Line: 257)
Drupal\Core\Entity\ContentEntityStorageBase->doSave(NULL, Object) (Line: 392)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 796)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 377)
Drupal\Core\Entity\Entity->save() (Line: 286)
Drupal\node\NodeForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 585)
Drupal\Core\Form\FormBuilder->processForm('node_page_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm('node_page_form', Object) (Line: 48)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object) (Line: 113)
Drupal\node\Controller\NodeController->add(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 153)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 38)
Drupal\webprofiler\StackMiddleware\WebprofilerMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 657)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)| Comment | File | Size | Author |
|---|---|---|---|
| #16 | 2942497-14-16.txt | 1005 bytes | scott_euser |
| #16 | content-moderation-preview-exception-2942497-16.patch | 2.11 KB | scott_euser |
| #14 | 2942497-11-14.txt | 600 bytes | scott_euser |
| #14 | content-moderation-preview-exception-2942497-14.patch | 1.75 KB | scott_euser |
| #12 | content-moderation-preview-exception-2942497-11.patch | 1.82 KB | scott_euser |
Comments
Comment #2
malcomio commentedI think the appropriate fix may be to hide the moderation state form in preview mode.
When editing an existing node, the form does not appear on the preview.
Comment #3
timmillwoodI guess we should prevent the moderation form from being shown on preview?
Comment #4
timmillwood#2914873: The "from state" used for calculating available transitions is changed when using the content moderation state widget and preview mode
Comment #5
berdirYes, that shouldn't be shown on preview.
Comment #6
scott_euser commentedI've attached a patch that bails showing the EntityModerationForm when in preview mode. I didn't see any existing tests covering the EntityModerationForm when viewing a node for instance. Can someone point me in the right direction? Then I can add test coverage to ensure the EntityModerationForm is not show when in preview mode.
Comment #7
timmillwoodLooks good, should be all we need, but needs a test to prevent future regressions.
Comment #8
scott_euser commentedThanks - could you point me in the direction of existing tests covering the EntityModerationForm when viewing the node? I couldn't find it anywhere. If it doesn't yet exist, happy to create a new test (and perhaps a separate issue to add test coverage for the form).
Comment #9
timmillwoodThis is where we test it: http://cgit.drupalcode.org/drupal/tree/core/modules/content_moderation/t...
Comment #10
scott_euser commentedGreat, thanks!
Comment #11
scott_euser commentedUpdated patch with test
Comment #12
scott_euser commentedComment #14
scott_euser commentedUpdated patch
Comment #15
berdirCan we add another assert to make sure that we are on the preview page?
We've had similar tests not-fail in the past because for some reason, we weren't on the expected page, for example if there is a validation error in the previous step.
Comment #16
scott_euser commentedThanks for the review and feedback - makes sense! Updated patch.
Comment #17
timmillwoodThanks for your persistence with this @scott_euser, looks good to me!
Comment #18
alexpottCrediting reviewers and @malcomio for discovering and opening the issue.
Comment #19
alexpottCommitted and pushed b6890803c1 to 8.6.x and 9fa428b4b8 to 8.5.x. Thanks!
Backported to 8.5.x since this is a bugfix for a module that is becoming stable in 8.5.0.
Comment #22
scott_euser commentedThanks all!
Thanks, yeah took me a bit to get the test working - quite a long test class and turns out the 'message' column of simpletest with type 'text' was too short to handle --verbose (or at least in my docker setup using Wodby's docker4drupal with Mariadb). Anyways, glad it's working and sorted!