Just minor bug caused by #1003788: PostgreSQL: PDOException:Invalid text representation when attempting to load an entity with a string or non-scalar ID. Found in the latest release Drupal 7.37.

<?php
function drupal_schema_field_types($table) {
  $table_schema = drupal_get_schema($table);
  foreach ($table_schema['fields'] as $field_name => $field_info) {
    $field_types[$field_name] = isset($field_info['type']) ? $field_info['type'] : NULL;
  }
  return $field_types;
}
?>

$field_types should be defined before foreach ( ... ).

CommentFileSizeAuthor
#1 2494403-7.x-field-types.patch434 bytesanydigital
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

anydigital’s picture

FileSize
434 bytes

Attaching the patch.

stefan.r’s picture

Status: Needs review » Reviewed & tested by the community

patch looks good

stefan.r’s picture

As the actual warnings are:

Warning: Invalid argument supplied for foreach() in drupal_schema_field_types() (line 7151 of /includes/common.inc).
Notice: Undefined variable: field_types in drupal_schema_field_types() (line 7154 of /includes/common.inc).
Warning: array_keys() expects parameter 1 to be array, null given in drupal_schema_fields_sql() (line 7171 of /includes/common.inc).

From David_Rothstein, this actually only fixes the notice and not the warnings:

That patch looks fine, but it will only fix the notice, right (not the two warnings)?

Seems to me like the cause of all three of them is actually a problem elsewhere in the code, most likely an entity which defines a 'base table' in hook_entity_info() that doesn't have a corresponding database schema in hook_schema()... I would also expect that one of those PHP warnings would appear before Drupal 7.37 too (since the patch here added drupal_schema_field_types() but did not do anything with drupal_schema_fields_sql()).

matthand’s picture

I experience this error on a fresh install that is also running the contrib modules UUID, File Entity, and Entity UUID. It seems there's a conflict between File Entity and Entity UUID that makes the schema object on File Entities not match the database table (file_managed). Just as you say, this patch only fixed the notice and not the warnings. Also, the warnings are triggered when viewing a file entity or flushing cache. I'll keep debugging the other modules but wanted to confirm to you that your assumptions are correct about a malformed entity.

David_Rothstein’s picture

Version: 7.37 » 7.x-dev
Status: Reviewed & tested by the community » Fixed

Committed to 7.x - thanks!

Status: Fixed » Closed (fixed)

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