Ajax integrity constraint on uuid with autosave and ajax-compatible confirmation type

Created on 22 September 2018, over 6 years ago
Updated 8 April 2024, 9 months ago

I'm somewhat arbitrarily marking this as major - (it might be an issue in core though?)

For this to occur you need Automatically save as draft when paging, previewing, and when there are validation errors, and a confirmation type like inline, that still uses AJAX to submit the form when there are no validation errors.

The attached .yml has a simple two field webform and all the settings (steps to reproduce included in an html element).

Submit a form that's only partially complete and it will, as desired, give you a required error, and in the background will save a draft. But then, when you go to submit again (regardless of whether you've fixed the error), the ajax response shows an integrity constraint violation on the uuid, because it's trying to insert the uuid of the existing draft:

ResponseText: The website encountered an unexpected error. Please try again later.Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '7fff7d90-8f64-49fa-bf0a-16731a71f956' for key 'webform_submission_field__uuid__value': INSERT INTO {webform_submission} (webform_id, uuid, langcode, serial, token, uri, created, completed, changed, in_draft, current_page, remote_add etc. etc.

It doesn't happen if you disable drafts, because partially completed forms don't get saved with drafts off.

(off topic: I think the UI of admin/structure/webform/manage/ajax_test/settings/submissions, when you manually refresh it is a bit misleading, because with drafts disable, both 'allow users to user multiple drafts' and 'Automatically save as draft when…' are visible, when they get hidden by JS when the main Drafts setting is changed to disabled - kind of implies 'Automatically save' will still work with drafts off.)

Tested on Drupal 8.6.1 and latest Webform 8.x-5.x dev branch.

πŸ› Bug report
Status

Needs review

Version

6.2

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom wturrell

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • I think I got a way to trigger this bug.

    My webform is very long and i have selected the option 'Automatically save as draft when paging, previewing, and when there are validation errors.' in my webform > parameters > Submissions > Submission Draft Settings.
    For some required fields, there is no html validation (a checkboxes field in my case).
    So when i submit the form (i realy mean submit, not save as draft) with this field not completed, it is send in ajax, validated server side, saved (due to the config) and a error message is display (the field is required).
    Then i fill the required field and re-submit the form.
    And this way, i got the error Integrity constraint violation: 1062 Duplicate entry '6f0cd0e6-da2d-4b44-a604-be9a5e706366' for key 'webform_submission_field__uuid__value&#039

    Hope this will help.

  • πŸ‡¬πŸ‡§United Kingdom wturrell

    FYI, I continue to successfully use the four-year-old patch.

    (minor reroll attached, in use with webform 6.2.0-beta4)

  • Status changed to Needs review 9 months ago
  • πŸ‡ΊπŸ‡ΈUnited States jrockowitz Brooklyn, NY

    Marking needs review based on #33.

Production build 0.71.5 2024