Steps to reproduce :
1- use a single field (any type, text will do)
2- edit a node, assign a value to the field, save the node
3- reedit the node, empty the value, save the node
The node keeps the value assigned in step 2
This is because we provide call drupal_write_record in 'update mode', with a record like
array('nid' => x, 'vid' => y, 'field_foo' => NULL)
drupal_write_record overlooks the NULL entry and doesn't update field_foo.
Not sure if that's the intended behavior. Seems strange that drupal_write_record cannot be used to set a column to NULL. Moshe ?
Comments
Comment #1
yched commentedSide note : this happens on non-multiple fields only, because updating a multiple field drops all existing records for the vid and uses d_w_r in 'insert' mode.
Comment #2
moshe weitzman commentedYes, this is a bug which I had fixed but the fix was not accepted into D6. The fix has already been applied to D7. See http://drupal.org/node/181411. Hopefully someone will extract the right bits and post a patch for D6.
Comment #3
damien tournoud commentedCore
drupal_write_record()does not allow NULL fields to be set. The missing part of Moshe's patch resolve a slightly different issue (saving empty serialized fields).We could roll a patch for core
drupal_write_record()to manage insertion and update of NULL fields, but in the meantime, here is a patch that implement a customcontent_write_record().Comment #4
damien tournoud commentedUpon yched's comment, patch updated not to touch unset fields.
Comment #5
damien tournoud commentedOups, typo.
Comment #6
yched commentedI committed a slightly shorter version (without safety checks : if you try to set a 'not null' column to NULL, you get a SQL error - there are other similar cases). Thanks !
I need to turn this into a core patch. Not sure a fix in D6 core will cut it for us anyway. Do we want to go 'CCK requires D6.1' (when it exists) ?
Comment #7
moshe weitzman commented6.1 will likely have security fixes in it so depending on that is quite reasonable. i'd rather not maintain our own private version of this function. sets a bad example for other contribs.
Comment #8
yched commented@moshe : yes, you're probably right. We'll see when it gets released :-) Not too keen on maintaining a separate version of this sensitive beast either.
Comment #9
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #10
zaczek commentedThis fix seems to produce another problem: http://drupal.org/node/486206
Cheers,
Jakub