Steps to reproduce

  1. Start creating a new node which has a moderation workflow, e.g. node/add/page
  2. enter some text
  3. go to preview
  4. change moderation state, click apply
  5. go back to editing
  6. save
  7. /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 &#039;f0a2210f-bedd-4268-8456-67b95511a39e&#039; for key &#039;node_field__uuid__value&#039;: 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] =&gt; 
    [:db_insert_placeholder_1] =&gt; page
    [:db_insert_placeholder_2] =&gt; f0a2210f-bedd-4268-8456-67b95511a39e
    [:db_insert_placeholder_3] =&gt; en
)
 in <em class="placeholder">Drupal\Core\Entity\Sql\SqlContentEntityStorage-&gt;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-&gt;execute(Array, Array) (Line: 625)
Drupal\Core\Database\Connection-&gt;query(&#039;INSERT INTO {node} (vid, type, uuid, langcode) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3)&#039;, Array, Array) (Line: 87)
Drupal\Core\Database\Driver\mysql\Connection-&gt;query(&#039;INSERT INTO {node} (vid, type, uuid, langcode) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3)&#039;, Array, Array) (Line: 32)
Drupal\Core\Database\Driver\mysql\Insert-&gt;execute() (Line: 878)
Drupal\Core\Entity\Sql\SqlContentEntityStorage-&gt;doSaveFieldItems(Object) (Line: 257)
Drupal\Core\Entity\ContentEntityStorageBase-&gt;doSave(NULL, Object) (Line: 392)
Drupal\Core\Entity\EntityStorageBase-&gt;save(Object) (Line: 796)
Drupal\Core\Entity\Sql\SqlContentEntityStorage-&gt;save(Object) (Line: 377)
Drupal\Core\Entity\Entity-&gt;save() (Line: 286)
Drupal\node\NodeForm-&gt;save(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter-&gt;executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter-&gt;doSubmitForm(Array, Object) (Line: 585)
Drupal\Core\Form\FormBuilder-&gt;processForm(&#039;node_page_form&#039;, Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder-&gt;buildForm(&#039;node_page_form&#039;, Object) (Line: 48)
Drupal\Core\Entity\EntityFormBuilder-&gt;getForm(Object) (Line: 113)
Drupal\node\Controller\NodeController-&gt;add(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}() (Line: 582)
Drupal\Core\Render\Renderer-&gt;executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber-&gt;Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 153)
Symfony\Component\HttpKernel\HttpKernel-&gt;handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel-&gt;handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle-&gt;handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache-&gt;pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache-&gt;handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware-&gt;handle(Object, 1, 1) (Line: 38)
Drupal\webprofiler\StackMiddleware\WebprofilerMiddleware-&gt;handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware-&gt;handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel-&gt;handle(Object, 1, 1) (Line: 657)
Drupal\Core\DrupalKernel-&gt;handle(Object) (Line: 19)

Comments

malcomio created an issue. See original summary.

malcomio’s picture

I 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.

timmillwood’s picture

I guess we should prevent the moderation form from being shown on preview?

berdir’s picture

Yes, that shouldn't be shown on preview.

scott_euser’s picture

Status: Active » Needs review
StatusFileSize
new742 bytes

I'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.

timmillwood’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Looks good, should be all we need, but needs a test to prevent future regressions.

scott_euser’s picture

Thanks - 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).

timmillwood’s picture

scott_euser’s picture

Assigned: Unassigned » scott_euser

Great, thanks!

scott_euser’s picture

Status: Needs work » Needs review
StatusFileSize
new949 bytes

Updated patch with test

scott_euser’s picture

Status: Needs review » Needs work
scott_euser’s picture

Status: Needs work » Needs review
StatusFileSize
new1.75 KB
new600 bytes

Updated patch

berdir’s picture

+++ b/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php
@@ -80,6 +80,16 @@ public function testModerationForm() {
+
+    // The preview view should not have a moderation form.
+    $this->assertResponse(200);
+    $this->assertNoField('edit-new-state', 'The node preview page has no moderation form.');

Can 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.

scott_euser’s picture

Thanks for the review and feedback - makes sense! Updated patch.

timmillwood’s picture

Assigned: scott_euser » Unassigned
Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Thanks for your persistence with this @scott_euser, looks good to me!

alexpott’s picture

Crediting reviewers and @malcomio for discovering and opening the issue.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 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.

  • alexpott committed b689080 on 8.6.x
    Issue #2942497 by scott_euser, timmillwood, malcomio, Berdir: Using...

  • alexpott committed 9fa428b on 8.5.x
    Issue #2942497 by scott_euser, timmillwood, malcomio, Berdir: Using...
scott_euser’s picture

Thanks all!

Thanks for your persistence with this @scott_euser, looks good to me!

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!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.