Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.1138 diff -u -r1.1138 common.inc --- includes/common.inc 28 Mar 2010 10:46:36 -0000 1.1138 +++ includes/common.inc 29 Mar 2010 04:42:56 -0000 @@ -5746,12 +5746,9 @@ } if (!property_exists($object, $field)) { - // Skip fields that are not provided, unless we are inserting and a - // default value is provided by the schema. - if (!empty($primary_keys) || !isset($info['default'])) { - continue; - } - $object->$field = $info['default']; + // Skip fields that are not provided, default values are already known + // by the database. + continue; } // Build array of fields to update or insert. @@ -5841,6 +5838,15 @@ $return = FALSE; } + // If we are inserting, populate empty fields with default values. + if (empty($primary_keys)) { + foreach ($schema['fields'] as $field => $info) { + if (!property_exists($object, $field) && isset($info['default'])) { + $object->$field = $info['default']; + } + } + } + // If we began with an array, convert back so we don't surprise the caller. if ($array) { $object = (array) $object;