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.


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/

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)) {
        // 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)) {

Members fund testing for the Drupal project. Drupal Association Learn more


dbu’s picture

note: 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.

quicksketch’s picture

Thanks 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.

claar’s picture

Ran into this today -- the work-around in a separate module still works. Thanks!

Liam Morland’s picture

Version: 7.x-3.x-dev » 7.x-4.x-dev
Status: Active » Needs review
Issue tags: +PostgreSQL
604 bytes

Here 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.

mscalone’s picture

Status: Needs review » Reviewed & tested by the community
613 bytes

The 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

quicksketch’s picture

Title: bug with file field and postgres » Empty file field causes error on Postgres
Status: Reviewed & tested by the community » Fixed

Thanks guys! Finally committed.

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