how to reproduce:
have drupal 7 with a postgres database, create a form with an optional file upload field and submit the form without a file.
behaviour:
PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for integer: "" LINE 4: WHERE (base.fid IN ('')) ^: SELECT base.fid AS fid, base.uid AS uid, base.filename AS filename, base.uri AS uri, base.filemime AS filemime, base.filesize AS filesize, base.status AS status, base.timestamp AS timestamp, base.uuid AS uuid FROM {file_managed} base WHERE (base.fid IN (:db_condition_placeholder_0)) ; Array ( [:db_condition_placeholder_0] => ) in DrupalDefaultEntityController->load() (Zeile 196 von /home/david/liip/clientis/clientis/includes/entity.inc).
i did not test with mysql, maybe it is more tolerant and this is why the bug does not show.
i can fix this by adjusting webform_webform_submission_presave to skip files with empty values.
foreach ($node->webform['components'] as $cid => $component) {
if ($component['type'] == 'file') {
$has_file_components = TRUE;
if (!empty($submission->data[$cid]['value'])) {
// FIX: remove empty values from array
foreach ($submission->data[$cid]['value'] as $key => $value) {
if (empty($value)) {
unset($submission->data[$cid]['value'][$key]);
}
}
// END FIX
$new_fids = array_merge($new_fids, $submission->data[$cid]['value']);
}
}
}
workaround: create a custom module with this hook to unset the offending empty entries
function mymodule_webform_submission_presave($node, &$submission) {
if (isset($submission->file_usage)) {
foreach ($submission->file_usage as $key => $files) {
foreach ($files as $index => $fid) {
if (empty($fid)) {
unset($submission->file_usage[$key][$index]);
}
}
}
}
}
Comments
Comment #1
dbu commentednote: i did not investigate with the 7.x-4 branch and did not find the method in the code there. maybe it only affects this branch - or there was refactoring later and you need to fix it there too.
Comment #2
quicksketchThanks for the report. I should be able to solve this problem without checking PostGres based on your solution. In any case, we shouldn't try to save empty data to the database anyway, so this fix for PostGres may have the nice side-effect of saving less data for other database systems also.
Comment #3
claar commentedRan into this today -- the work-around in a separate module still works. Thanks!
Comment #4
liam morlandHere is the fix to webform_webform_submission_presave() as a patch to 7.x-4.x-dev. I haven't tested it; it's a direct copy.
Comment #5
mscalone commentedThe patch #4 does not work on 7.x-3.x branch because of wrong line number.
I'm attaching this one (essentially the same code but) tested on 7.x-3.x, generated from 7.x-3.x-dev
Comment #6
quicksketchThanks guys! Finally committed.