drupal_write_record has the ability to detect when it is passed an incomplete object (based on the schema) to insert into the database. This patch makes it log an error when this occurs. The behavior of the function is not changed in any other way.

This patch will make missing-field bugs that mysql hides with its stupid "implicit default values" property show up in the log.

Comments

moshe weitzman’s picture

what if one alters schema to add a field to node table (for example). most of the queries will not specify that field and use the schema default which is desired behaviors. we would be logging many useless messages. so there is a tradeoff here.

yched’s picture

If I read the patch correctly, logging occurs when no column default is found in the schema.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

oh, you are right. so this is rtbc. we usually do the else clause on a new line and combine into elseif but thats minor. hopefully gabor can fix that if noone else gets to it.

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Needs work

Hm, Drupal does not use trigger_error(), but watchdog and its constants instead. (Additionally to the coding style error noted by Moshe)

pancho’s picture

Category: feature » task

This is more a bug than a new feature, therefore I keep it in the D6 queue. Needs to be rerolled according to #3 and #4.

pancho’s picture

Version: 6.x-dev » 7.x-dev

Now this needs to go to D7.

brianV’s picture

Status: Needs work » Needs review
StatusFileSize
new2.13 KB

Here's the patch rolled for D7.

mcarbone’s picture

StatusFileSize
new1.94 KB

Tested this on HEAD and it works well. One minor question: it's currently using WATCHDOG_ERROR as the severity. Should it instead be WATCHDOG_WARNING (since, for instance, MySQL -- at least 5.1 -- will still insert the row with a NULL value)?

Re-rolled to fix the minor coding style issue.

MichaelCole’s picture

#8: 193960-log-missing-field.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 193960-log-missing-field.patch, failed testing.

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.