Problem/Motivation
When uploading a CSV file via a managed_file form element in Drupal 11, This causes a fatal error during loading csv file.
The website encountered an unexpected error. Try again later.
Exception: Serialization of 'Symfony\Component\HttpFoundation\File\UploadedFile' is not allowed in serialize() (line 14 of core/lib/Drupal/Component/Serialization/PhpSerialize.php).
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | Captura desde 2025-10-20 17-41-41.png | 16.43 KB | saibher |
| Captura desde 2025-10-20 17-19-28.png | 50.01 KB | saibher |
Comments
Comment #2
saibher commentedThe error occurs because the form is cached in Drupal 11 in a way that prevents serialization.
To correctly load the files, disable the cache on the form state as follows:
$form_state->disableCache();
Comment #3
quietone commentedHi, in Drupal core changes are made on on 11.x (our main development branch) first, and are then back ported as needed according to the Core change policies.
Changing tags per Issue tags field and Issue tags -- special tags
Thanks.
Comment #4
cilefen commentedThis CSV import doesn't seem to be Drupal Core functionality. What are the modules needed to reproduce the bug?
Comment #6
matthiasm11 commentedI can confirm this bug.
I have a custom entity with:
Adding the following lines fixes the issue, but this should probably be fixed in core. I haven't had the time to look into it.
Comment #7
cilefen commentedSo, is this unrelated to CSVs? The issue title and summary specifies CSVs.
This needs proper steps to reproduce in the issue summary and a title update, or it will languish.