Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.1151 diff -u -r1.1151 common.inc --- includes/common.inc 24 Apr 2010 14:53:59 -0000 1.1151 +++ includes/common.inc 26 Apr 2010 14:50:23 -0000 @@ -5729,8 +5729,7 @@ $fields = array(); - // Go through our schema, build SQL, and when inserting, fill in defaults for - // fields that are not set. + // Go through the schema to determine fields to write. foreach ($schema['fields'] as $field => $info) { if ($info['type'] == 'serial') { // Skip serial types if we are updating. @@ -5743,12 +5742,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. @@ -5838,6 +5834,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;