When I submit a story node as an authenticated user, I get the following warnings and the record in the node_revisions table is NOT inserted:
warning: pg_query() [function.pg-query]: Query failed: ERROR: null value in column "log" violates not-null constraint in /var/www/drupal-cvs/includes/database.pgsql.inc on line 155.
user warning: query: INSERT INTO node_revisions (nid, uid, title, body, teaser, timestamp, format) VALUES (6, 5, 'Een verhaal', 'Dit is om te testen.', 'Dit is om te testen.', 1193918832, 1) in /var/www/drupal-cvs/includes/common.inc on line 3187.
When I do the same thing as the administrator (user 1), the error doesn't occur because in that case the story form includes a log field.
The site runs on a Postgresql database. Maybe MySQL shows a similar error only when running in strict mode?
The solution can be to change the definition of the node_revisions table by giving the log field a default value of ''. At present, the log field is often not filled in, so the value will be '' anyways.
A patch for the node.install file is included for new installs, but not to update present installations.
An existing table can be altered by:
alter table node_revisions alter column log set default '';
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | node.module.patch | 867 bytes | jpulles |
| #7 | node-log-null-188462-7.patch | 944 bytes | bjaspan |
| #2 | system.install.patch | 651 bytes | jpulles |
| node.install.patch | 622 bytes | jpulles |
Comments
Comment #1
catchThis will need an update path to get committed, so marking as needs work for that.
Comment #2
jpulles commentedThe attached system.install.patch should update the node_revisions table in the database. Both this patch and the previous one (node.install.patch) are needed for this issue.
Comment #3
gábor hojtsyAs pointed out elsewhere by bjaspan (http://drupal.org/node/190128) the problem here is that MySQL does not allow default values for TEXT fields, so we cannot do this in the schema. But PostgreSQL does not use an empty default when a field is not provided, so this end up in the error. An empty log field should be in the SQL insert which runs, that solves the problem.
Comment #4
bjaspan commentedI'm wondering if we should change db_write_record() to enforce that not-null no-default columns must have values for INSERT; it would flush out all of these bugs at once. Anyway, I'll make a patch for this issue soon.
Comment #5
bjaspan commented(I appear to have forgotten about this. I wish project.module let me flag issues; I'd use it for "there is something I want to do but have not yet for this issue, don't forget to get back to it.")
I just tried to reproduce this problem with pgsql before making a patch and got so many error messages it is impossible to continue. It looks like menu, taxonomy, and forum modules have lots of problems. I'll try again tomorrow, hopefully.
Comment #6
keith.smith commentedI marked http://drupal.org/node/192583 as a duplicate of this issue.
Comment #7
bjaspan commentedThe attached patch fixes this bug in node_save() by setting an empty $node->log when a new node is being created and no log field is provided. With this patch, non-admin users can create nodes on pgsql.
I'm not convinced this is the best solution from API design point of view. node_save() can require that it be given a valid object and "no log field for a new node" can be declared an invalid object. In that case, the right solution might be to add a #type value form element named log with an empty value when the user is not allowed to specify a log message.
Of course, the data APIs are likely to change completely in D7 so getting this exactly right may not be relevant.
Comment #8
webernet commentedThis issue was addressed at least once before... http://drupal.org/node/100850
Please ensure that the log messages work as follows:
- New nodes use either blank or provided message.
- Edited nodes (without create new revision checked) use the old log value, or use the new value if it exists (perhaps append it to the existing message?)
- Edited nodes (with create new revision checked) use either blank or provided message.
Comment #9
gábor hojtsywebernet: I tested bjaspan's patch on MySQL and also accurately checked your list, although I don't think that it relates to fixing this pgsql bug.
They do. (if create revision is checked).
They do keep the old log value, if nothing is specified (the old value does not appear in the form). If a new value is specified, the old value is replaced.
This is how it works.
Committed bjaspan's patch, thanks!
Comment #10
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #11
jpulles commentedThis issue is reopened because the same bug occurred (Drupal 6.1, PostgreSQL database) when a normal user was editing a node type which automatically creates revisions for non-administrators. In that case the log value was missing also. A patch is attached.
Of course It can be argued that the log value should also be set when the node type sets the "$node->revision = 1", but it seems preferrable to me to have this check in the node module.
The error is reproducible using the book module if a 'normal' user has permissions to add child pages to books. When he updates a child page, the error occurs. Code in the book module:
// Always save a revision for non-administrators.
if (!empty($node->book['bid']) && !user_access('administer nodes')) {
$node->revision = 1;
}
Comment #12
David_Rothstein commentedIt looks like this is related to #261258: Fix node_save() insertion logic...
Comment #13
damien tournoud commentedPlease see #261258: Fix node_save() insertion logic for a more general fix for that (and related) issues in
node_save().Comment #14
panchoThis is no duplicate as the original issue has been solved and the original patch committed. See also #195169: NOT NULL fields need default value.
Comment #15
gpk commentedI think the point is that the problem turned out to be bigger than originally realised and recurred at #11. #261258: Fix node_save() insertion logic still looks to be the best hope of a fix. Another related issue: #223820: Book module tests for postgres error.