Problem/Motivation

When I try to attach a file in a webform, I get an error
Exception: Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed in serialize() (line 497 of docroot/modules/contrib/webform/src/Entity/WebformSubmission.php).

Steps to reproduce

1.Update Drupal to version 9.5.0
2. Create a web form with a field for a file (private file mode)
3. Try to attach a file

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

WiseMike created an issue. See original summary.

Anas_maw’s picture

I'm having the same issue, once the webform includes select or other and a visible condition on this field.
Also I tried it on a fresh installation on fresh Drupal and the issue still exists

cilefen’s picture

Priority: Critical » Major
Issue tags: +Needs steps to reproduce
Anas_maw’s picture

Here is a simple form for this issue:

uuid: 49169286-cc04-4d53-8b8c-3c5d595bd46a
langcode: en
status: open
dependencies:
  module:
    - entity_redirect
third_party_settings:
  entity_redirect:
    redirect:
      add:
        active: 0
        destination: default
        url: ''
        external: ''
      edit:
        active: 0
        destination: default
        url: ''
        external: ''
      delete:
        active: 0
        destination: default
        url: ''
        external: ''
      anonymous:
        active: 0
        destination: default
        url: ''
        external: ''
weight: 0
open: null
close: null
uid: 1
template: false
archive: false
id: test
title: test
description: ''
category: ''
elements: |-
  options:
    '#type': radios
    '#title': options
    '#options':
      options1: options1
      option2: option2
    '#required': true
    '#default_value': options1
  select:
    '#type': webform_select_other
    '#title': Select
    '#options':
      1: '1'
      2: '2'
      3: '3'
    '#states':
      visible:
        ':input[name="options"]':
          value: options1
  files:
    '#type': managed_file
    '#title': files
    '#multiple': true
    '#required': true
css: ''
javascript: ''
settings:
  ajax: false
  ajax_scroll_top: form
  ajax_progress_type: ''
  ajax_effect: ''
  ajax_speed: null
  page: true
  page_submit_path: ''
  page_confirm_path: ''
  page_theme_name: ''
  form_title: both
  form_submit_once: false
  form_open_message: ''
  form_close_message: ''
  form_exception_message: ''
  form_previous_submissions: true
  form_confidential: false
  form_confidential_message: ''
  form_disable_remote_addr: false
  form_convert_anonymous: false
  form_prepopulate: false
  form_prepopulate_source_entity: false
  form_prepopulate_source_entity_required: false
  form_prepopulate_source_entity_type: ''
  form_unsaved: false
  form_disable_back: false
  form_submit_back: false
  form_disable_autocomplete: false
  form_novalidate: false
  form_disable_inline_errors: false
  form_required: false
  form_autofocus: false
  form_details_toggle: false
  form_reset: false
  form_access_denied: default
  form_access_denied_title: ''
  form_access_denied_message: ''
  form_access_denied_attributes: {  }
  form_file_limit: ''
  form_attributes: {  }
  form_method: ''
  form_action: ''
  share: false
  share_node: false
  share_theme_name: ''
  share_title: true
  share_page_body_attributes: {  }
  submission_label: ''
  submission_exception_message: ''
  submission_locked_message: ''
  submission_log: false
  submission_excluded_elements: {  }
  submission_exclude_empty: false
  submission_exclude_empty_checkbox: false
  submission_views: {  }
  submission_views_replace: {  }
  submission_user_columns: {  }
  submission_user_duplicate: false
  submission_access_denied: default
  submission_access_denied_title: ''
  submission_access_denied_message: ''
  submission_access_denied_attributes: {  }
  previous_submission_message: ''
  previous_submissions_message: ''
  autofill: false
  autofill_message: ''
  autofill_excluded_elements: {  }
  wizard_progress_bar: true
  wizard_progress_pages: false
  wizard_progress_percentage: false
  wizard_progress_link: false
  wizard_progress_states: false
  wizard_start_label: ''
  wizard_preview_link: false
  wizard_confirmation: true
  wizard_confirmation_label: ''
  wizard_auto_forward: true
  wizard_auto_forward_hide_next_button: false
  wizard_keyboard: true
  wizard_track: ''
  wizard_prev_button_label: ''
  wizard_next_button_label: ''
  wizard_toggle: false
  wizard_toggle_show_label: ''
  wizard_toggle_hide_label: ''
  wizard_page_type: container
  wizard_page_title_tag: h2
  preview: 0
  preview_label: ''
  preview_title: ''
  preview_message: ''
  preview_attributes: {  }
  preview_excluded_elements: {  }
  preview_exclude_empty: true
  preview_exclude_empty_checkbox: false
  draft: none
  draft_multiple: false
  draft_auto_save: false
  draft_saved_message: ''
  draft_loaded_message: ''
  draft_pending_single_message: ''
  draft_pending_multiple_message: ''
  confirmation_type: page
  confirmation_url: ''
  confirmation_title: ''
  confirmation_message: ''
  confirmation_attributes: {  }
  confirmation_back: true
  confirmation_back_label: ''
  confirmation_back_attributes: {  }
  confirmation_exclude_query: false
  confirmation_exclude_token: false
  confirmation_update: false
  limit_total: null
  limit_total_interval: null
  limit_total_message: ''
  limit_total_unique: false
  limit_user: null
  limit_user_interval: null
  limit_user_message: ''
  limit_user_unique: false
  entity_limit_total: null
  entity_limit_total_interval: null
  entity_limit_user: null
  entity_limit_user_interval: null
  purge: none
  purge_days: null
  results_disabled: false
  results_disabled_ignore: false
  results_customize: false
  token_view: false
  token_update: false
  token_delete: false
  serial_disabled: false
access:
  create:
    roles:
      - anonymous
      - authenticated
    users: {  }
    permissions: {  }
  view_any:
    roles: {  }
    users: {  }
    permissions: {  }
  update_any:
    roles: {  }
    users: {  }
    permissions: {  }
  delete_any:
    roles: {  }
    users: {  }
    permissions: {  }
  purge_any:
    roles: {  }
    users: {  }
    permissions: {  }
  view_own:
    roles: {  }
    users: {  }
    permissions: {  }
  update_own:
    roles: {  }
    users: {  }
    permissions: {  }
  delete_own:
    roles: {  }
    users: {  }
    permissions: {  }
  administer:
    roles: {  }
    users: {  }
    permissions: {  }
  test:
    roles: {  }
    users: {  }
    permissions: {  }
  configuration:
    roles: {  }
    users: {  }
    permissions: {  }
handlers:
  debug:
    id: debug
    handler_id: debug
    label: Debug
    notes: ''
    status: true
    conditions: {  }
    weight: 0
    settings:
      format: yaml
      submission: false
variants: {  }
WiseMike’s picture

I'm having the same issue, once the webform includes select or other and a visible condition on this field.

That's a great point! I checked on the site where the problem occurred. If I remove a visible condition from the file field, attaching files works without errors.

Also works if the form has select or other fields without a visible condition on the field file

dureaghin’s picture

I tested with Webform 6.1.2, same issue..

Drupal 9.5.0
PHP 8.1.13
MySQL 8.0.30

cilefen’s picture

Status: Active » Postponed (maintainer needs more info)

Can someone confirm that this is the core bug?

WiseMike’s picture

Duplicate issue: https://www.drupal.org/project/webform/issues/3213580

It's not duplicate issue. Because before I updated Drupal to 9.5.0, the file upload fields worked fine through conditionnal logic, with no errors.

Can someone confirm that this is the core bug?

I did not install any new modules. Probably affected by an update of Drupal or some module. I can not confirm in detail, because I am not a programmer

Anas_maw’s picture

Status: Postponed (maintainer needs more info) » Active

This issue is not related to the core bug, please import the form I attached in comment 4
I tried this form on a fresh Drupal installation, the issue happens when there is a webform handler and there is a 'select or other' element in the webform

ecvandenberg’s picture

I can confirm #9.

Removing the conditional view for the file upload field and also disable the e-mail handler solved the issue.
Both were required.

I wish I could debug more, but I'm no coder. I will donate in stead :-)

SlayJay’s picture

Same issue for me... Downgrading to Drupal 9.4.9 fixes the problem for me

cilefen’s picture

Some reporters are directly pointing to a Drupal Core bug and others insist it is not a Core bug.

Are there multiple causes (or even multiple bugs?) or do we need more tightly specified steps to reproduce?

vuil’s picture

We received the same error page (blank) after a webform submission with attached file/s on Drupal 9.5.0 & PHP 8.1:

The website encountered an unexpected error. Please try again later.

Exception: Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed in serialize() (line 497 of modules/contrib/webform/src/Entity/WebformSubmission.php).
Drupal\webform\Entity\WebformSubmission->getDataHash() (Line: 360)
Drupal\webform\Plugin\WebformHandlerBase->checkConditions(Object) (Line: 2775)
Drupal\webform\Entity\Webform->isHandlerEnabled(Object, Object) (Line: 2719)
Drupal\webform\Entity\Webform->invokeHandlers('overrideSettings', Object) (Line: 508)
Drupal\webform\WebformSubmissionForm->overrideSettings(Object) (Line: 493)
Drupal\webform\WebformSubmissionForm->buildEntity(Array, Object) (Line: 497)
Drupal\webform\WebformSubmissionConditionsValidator::elementValidate(Array, Object, Array)
call_user_func_array(Array, Array) (Line: 282)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'webform_submission_send_us_copies_of_your_documents_add_form') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('webform_submission_send_us_copies_of_your_documents_add_form', Array, Object) (Line: 591)
Drupal\Core\Form\FormBuilder->processForm('webform_submission_send_us_copies_of_your_documents_add_form', Array, Object) (Line: 323)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 48)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object, 'add') (Line: 1243)
Drupal\webform\Entity\Webform->getSubmissionForm() (Line: 76)
Drupal\webform\Controller\WebformEntityController->addForm(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 580)
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}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 707)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

We are already applied the mentioned in #6 Drupal core patch.

The webform_attachment is enabled.

Is it possible someone to check with a disabled cache as it is already applied onto views_bulk_edit module here: #2974237: Serialization exception when trying to edit a file/image field

vuil’s picture

Version: 6.1.3 » 6.1.x-dev
vuil’s picture

Downgrade of drupal/core from 9.5.0 to 9.4.9 makes our webforms with attachment files back to work for us too. The same as #11.

jrockowitz’s picture

Status: Active » Postponed (maintainer needs more info)
FileSize
5.19 KB

I cannot replicate this issue via Webform 6.2.x or 6.1.x and Drupal 9.5.1 using the attached webform based on #4, which had a dependency on the entity_redirect.module.

Please provide the elements and steps required to reproduce this issue.

jrockowitz’s picture

The good news is the method that is throwing the error should be very easy to tweak not to serialize the object.

@see \Drupal\webform\Entity\WebformSubmission::getDataHash

jrockowitz’s picture

Now I see that you need to add a handler to replicate this bug.

jrockowitz’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
1019 bytes

Please take a look at the attached patch. Once this patch is reviewed, I will merge it and new beta releases.

alberto56’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs steps to reproduce

I'll set this to "RTBC" based on the following:

(1) I have tested this and it fixes the issue on a production environment

(2) WebformSubmission::getDataHash() seems to only be used by WebformHandlerBase::checkConditions() to cache its results based on a form submission's field values.

With this patch, the hash will be identical regardless of the content of an object which is included in submission results. Specifically, any information included within the Symfony\Component\HttpFoundation\File\UploadedFile is not serialized and not part of the hash value.

I checked in handler's "condition" tab if such information can actually be used to determine the validity of a handler; and I have concluded that conditions do not seem to apply to file information contained in those objects (with the caveat that I don't use handler conditions in my production environments so I might not have considered all possibilities).

Therefore, the lack of object information within the serialized data used to generate the hash does not seem make it possible for two result sets (one for which handler conditions are valid and another for which they are invalid) to result in the same hash.

ecvandenberg’s picture

Patch #19 solves the issue in my config (drupal 9.5.0, webform 6.1.3, php 7.4.33)

jrockowitz’s picture

This issue will impact all 6.x versions of the Webform module. I will commit the patch and tag new releases.

jrockowitz’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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