Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293850

Saving an Image field with an image that has undeterminable dimensions throws PDOException.

$
0
0

Updated: Comment #57

Problem/Motivation

I see a lot of issues about this error in various contrib modules, but it is not exclusively a contrib problem and can happen with the core integer field as well as with contrib field types such as location field and node reference that store integer values in their respective field_data_field tables. To reproduce the problem, create an integer field (or location or node reference or...) with no default value, then create content without specifying a value for that field. The error is as follows:

PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'field_[field name here]' at row 1: INSERT INTO {field_data_field_[field name here]} (entity_type, entity_id, revision_id, bundle, delta, language, field_[field name]_value) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 5060 [:db_insert_placeholder_2] => 5310 [:db_insert_placeholder_3] => directory [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => ) in field_sql_storage_field_storage_write() (line 451 of /home/[account]/public_html/drupal-7.9/modules/field/modules/field_sql_storage/field_sql_storage.module).

Proposed resolution

The thing to notice here is that placeholder 6 is not an integer and is not NULL. There is some code in the function (lines 433-435 of field_sql_storage.module) that attempts to handle this:

<?php
 
foreach ($field['columns'] as $column => $attributes) {
    
$record[_field_sql_storage_columnname($field_name, $column)] = isset($item[$column]) ? $item[$column] : NULL;
  }
?>

but for some reason this is not sufficient to convert these non-values to NULL before sending them to the database. I replaced this with the following:

<?php
 
foreach ($field['columns'] as $column => $attributes) {
    
//convert non-numeric values (such as empty strings) in integer fields to NULL
    
if ($attributes['type'] == 'int'&& !$attributes['not null'] && !is_numeric($item[$column])) {
      
$item[$column] = NULL;
     }
    
$record[_field_sql_storage_columnname($field_name, $column)] = isset($item[$column]) ? $item[$column] : NULL;
  }
?>

and that has resolved the problem. I am terrible at rolling patches, so I'd appreciate it if someone who is more competent in that regard could review this fix and turn it into a proper patch. Thank you in advance.

Patches on comment #7 and #9

Check that GD is installed. Comment #39

Remaining tasks

Patches need testing


Viewing all articles
Browse latest Browse all 293850


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>