Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#19 | 3328986-19.patch | 1019 bytes | jrockowitz |
#18 | webform.webform.issue_3328986_files_cannot_be_at.yml | 5.39 KB | jrockowitz |
#16 | webform.webform.issue_3328986.yml | 5.19 KB | jrockowitz |
Comments
Comment #2
Anas_maw CreditAttribution: Anas_maw at Coders Enterprise Web & Mobile Solutions commentedI'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
Comment #3
cilefen CreditAttribution: cilefen commentedComment #4
Anas_maw CreditAttribution: Anas_maw at Coders Enterprise Web & Mobile Solutions commentedHere is a simple form for this issue:
Comment #5
WiseMike CreditAttribution: WiseMike commentedThat'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
Comment #6
dureaghin CreditAttribution: dureaghin commentedI tested with Webform 6.1.2, same issue..
Drupal 9.5.0
PHP 8.1.13
MySQL 8.0.30
duplicateissues: https://www.drupal.org/project/webform/issues/3213580 and https://www.drupal.org/project/webform/issues/3240636Comment #7
cilefen CreditAttribution: cilefen commentedCan someone confirm that this is the core bug?
Comment #8
WiseMike CreditAttribution: WiseMike commentedIt'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.
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
Comment #9
Anas_maw CreditAttribution: Anas_maw at Coders Enterprise Web & Mobile Solutions commentedThis 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
Comment #10
ecvandenberg CreditAttribution: ecvandenberg at Inforwijzer commentedI 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 :-)
Comment #11
SlayJay CreditAttribution: SlayJay commentedSame issue for me... Downgrading to Drupal 9.4.9 fixes the problem for me
Comment #12
cilefen CreditAttribution: cilefen commentedSome 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?
Comment #13
vuilWe received the same error page (blank) after a webform submission with attached file/s on Drupal 9.5.0 & PHP 8.1:
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 fieldComment #14
vuilComment #15
vuilDowngrade 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.Comment #16
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedI 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.
Comment #17
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedThe 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
Comment #18
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedNow I see that you need to add a handler to replicate this bug.
Comment #19
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedPlease take a look at the attached patch. Once this patch is reviewed, I will merge it and new beta releases.
Comment #20
alberto56 CreditAttribution: alberto56 at Dcycle commentedI'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.
Comment #21
ecvandenberg CreditAttribution: ecvandenberg at Inforwijzer commentedPatch #19 solves the issue in my config (drupal 9.5.0, webform 6.1.3, php 7.4.33)
Comment #22
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commentedThis issue will impact all 6.x versions of the Webform module. I will commit the patch and tag new releases.
Comment #23
jrockowitz CreditAttribution: jrockowitz as a volunteer and at Webform module Open Collective, The Big Blue House commented