The setup:
Drupal 6.0, Postgresql 8.1.11, php-5.2.5. Fresh install (no upgrade), no modules or themes, just one role and one user, next to USER1.
The problem: after creating a book page and editing this, an sql error is issued and no more content can be added at all. SQL errors are show below.
Steps to reproduce:
After installation create a new role (and a user afterwards) with following permissions:
Book Modules
Node module:
access content
create book content
delete own book content
edit own book content
revert revisions
view revisions
Path module:
create url aliases
Log in as user, create a book page, outline does not matter (wether new book or none), and save.
Logout
Login again
Edit Test page, try to save it, enjoy the error:
Page not found
• warning: pg_query() [function.pg-query]: Query failed: FEHLER: NULL-Wert in Spalte »log« verletzt Not-Null-Constraint in /home/www/cms/includes/database.pgsql.inc on line 138.
• user warning: query: INSERT INTO node_revisions (nid, uid, title, body, teaser, timestamp, format) VALUES (1, 3, 'First Test Page', 'Some test text. And now edited', 'Some test text. And now edited', 1203429965, 1) in /home/www/cms/includes/common.inc on line 3314.
Book page First Test Page has been updated.
The requested page could not be found.
I do not know how to tell drupal to report errors in english, especially as there is no german translation avaiable for 6.0, but I will try to translate:
Query failed, ERROR: Zero-Value in column "log" violates Not-Zero constraint in /home/www....
Now, for some more fun. Trying to create another, completely new and not related book produces following error upon saving:
Create Book page
• warning: pg_query() [function.pg-query]: Query failed: FEHLER: duplizierter Schlüssel verletzt Unique-Constraint »node_vid_key« in /home/www/cms/includes/database.pgsql.inc on line 138.
• user warning: query: INSERT INTO node (vid, type, language, title, uid, status, created, changed, comment, promote, moderate, sticky, tnid, translate) VALUES (0, 'book', '', '2nd Book', 3, 1, 1203430226, 1203430226, 0, 0, 0, 0, 0, 0) in /home/www/cms/includes/common.inc on line 3314.
• The post could not be saved.
Book page 2nd Book has been created.
Which, translated, reads something like: Query failed: ERROR: duplicated Key violates Unique-Constraint "node_vid_key"
But, of course, we are not done here and we log in an USER1 again
First of all, our first book (the first sql error) is still listed below the "book navigation" menu. However, trying to access this produces just a "page not found" site.
Going on to administer -> content management -> content for removing this site, after confirmation for deleting the site, the title is still present. And you can delete again and again, but it won’t go away.
So the system is basically completely fubar, as you cannot remove the rogue site and cannot create any new, too. Did not happen with drupal5 (so far).
I will gladly reconfigure drupal to report english messages, if told how to or attach an sql dump, if helpful.
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | 223820-core-book-empty-log.patch | 1.77 KB | damien tournoud |
| #20 | tests-223820-core-book-empty-log.patch | 3.83 KB | damien tournoud |
| #17 | d7-core-book-empty-log.patch | 1.77 KB | damien tournoud |
| #17 | d6-core-book-empty-log.patch | 1.78 KB | damien tournoud |
| #13 | d6-core-book-empty-log.patch | 1.59 KB | damien tournoud |
Comments
Comment #1
gpk commentedUnable to reproduce on my localhost installation which uses MySQL (although mine is not a new site and there are probably some other minor differences).
However it looks as though there is no default value defined for field {node_revisions.log} - see http://api.drupal.org/api/file/modules/node/node.install/6/source. Maybe MySQL uses empty string, whereas PgSQL throws an error.
Do you get the initial error with other content types? (This is the important error, since it prevents the node from being properly created and so the DB ends up with a mangled node/node revision entry.) I can't see anything much specific to book pages that would restrict your error to them.
Comment #2
druus commentedI am pretty sure that this error happened at least with pages too, haven't tried blogs so far. As a sidenote, this problem does not occur in Drupal 5.7, which also uses postgresql here.
I will confirm later when I have admin access to the database again, as I am currently not able to create any content at all, independend of the user, so I need to reinstall.
However, I wonder, if this happens on a production site, how to recover?
Comment #3
gpk commented>This problem does not occur in Drupal 5.7
That's because there was separate code for PgSQL that specified the field as
log text NOT NULL default ''. I suspect this may be an old bug that has been reintroduced with the new database schema API.>I am pretty sure that this error happened at least with pages too
Would be useful if you could confirm as this would mean 6.0 basically does not work witn pgSQL.
>how to recover?
It won't happen once the install code for the {node_revisions} table is fixed, if that is indeed the problem. In your case you would need as a minimum to delete the entry from the {node} table that corresponds to the node id of the page, and all entries from the {node_revisions} table with this node id. You may even be able to do this via the usual admin/content interface. Also if you created a menu item and/or book outline entry for the page then they would need to go as well. Potentially there are other links to other tables as well but hopefully you've not created any of those at this stage!
[Update:]
I think the critical thing which leads to this bug is that on the admin/content/node-type/book screen, under Workflow settings, "create new revision" is *not* checked. Therefore you don't get a "Log message" box on the node input/edit form, and as a result $node->log is not set, hence not even an empty string for $node->log is inserted in the DB.
Comment #4
druus commentedCannot confirm. Creating and editing ordinary pages worked. Also books work, when "create revisions" is set. It also makes a difference wether you outline the book or not. As long as you have "none" selected for book outline, one can edit as long as one wants. As soon as you try to create this page as a new book, you get this error.
Do not know wether this happens for subchapters, too
Comment #5
gpk commentedThanks,
>Creating and editing ordinary pages worked
Even when the "create new revision" box is unchecked on the content type admin page? If the Log message box is present on the create/edit form then this problem should not arise, so if you are operating as a user with "administer content" permissions I think you always get that box, hence should never have a problem. Can you confirm what happens creating an ordinary page with permissions set such that this box is *not* present?
>As long as you have "none" selected for book outline one can edit as long as one wants
Don't see how this fits with your permissions listed above for the "new" user - which show no permissions for book module. Previously you said "outline does not matter (wether new book or none)" - i.e. you always get the error. Sorry to nitpick, just trying to home in on the problem! Also I think that editing is not where the problem arises - it's when creating a new book page that the original problem occurred AFAICS.
>Also books work, when "create revisions" is set
At least that is what I would have expected! :-D
Comment #6
druus commented> which show no permissions for book module
This was an error in my post. Just figured out. Under "book modules" there was an "all" supposed to be. All issues are checked for that role. I probably put it into tags and have overseen it missing in my review. Sorry for that. The questioned role has in fact only (own) book and revision (w/o delete) permissions.
And nitpicking is perfectyl fine when I contradict myself.
I did some more tests yesterday, each with a "fresh" database. Luckily, drupal is easy to install. As an ordinary user with above (corrected) rights, I could create and edit a book page, as long as the outline was "none". Here I withdraw my "outline does not matter" satement.
Maybe the initial statement maybe arose, because I tried to change the outline after the initial sql error already occured.
So creating and editing a book page with no outline works. However, when I try to create a new book out of this already existing page afterwards, I get mentioned sql error, even if I do not change the text/content.
Creating an initial bookpage, which instantly becomes a new book, works, too. However, editing that bookpage produces the error. So the issue seems in deed to be more an issue with created books and/or creation of books.
Above has been done all as an ordinary user with the create revisions checkbox under content types NOT set. That is, I had no revision option whatsoever in my book page.
Maybe it should be noted, that if the user (role) has only rights to own books, the user is not able to actually access it own books after creation.
That is, I create a new book (creation on the first run does work, as mentioned), and immediately after saving I get an "access denied" page, telling me that I do not have permissions to access that site I just created.
However, logging in as USER1 under content management this site is listed as owned by that particular user - I currently only have one anyway.
Now, even after relogin as that user, I still cannot access nor edit this bookpage. So I have to grant access to "any books" just to edit my own bookpages. Thats why I mentioned the (corrected) rights above.
Ought to be an own issue, but maybe it's related.
To the pages:
Creating an ordinary (non book) page when checkbox "create revisions" under content types -> workflow is not set makes no problems. Editing pages with that checkbox set neither.
What I have not tested yet, is, wether it makes a difference when creating books as USER1 and checking (or unchecking) the revisions checkbox in the actual content creation page (not in the admin -> content types site).
Update:
The rights problem has vanished, I can edit own books, must have been an error in front of the PC. The rest stays:
revision NOT set (off for all content types):
editing pages / stories is ok
editing bookpages with no outline works
editing pages of created books or create books of previously none outlined bookpages produces named sql error
revisions IS set (on for all content types):
all works as advertised.
Comment #7
fmatias commentedI have the same druus's problem.
Posgresql 8.2.6, php 5.2.4.
Comment #8
gpk commentedOK this tiny patch adds a default value of empty string for {node.log} in hook_scheme() in node.install.
As noted above at #3, in Drupal 5.x the field is created as
log text NOT NULL default ''for Postgresql (butlog longtext NOT NULLfor MySQL) - see http://cvs.drupal.org/viewvc.py/drupal/drupal/modules/system/system.inst.... For some reason thedefault ''got removed from the MySQL definition at revision 1.48, but no issue is referenced so I'm not sure why.Especially since I only have MySQL I've not had time to trace back and work out why the problem only seems to happen in the situation described, but pls see if this patch helps.
Patch should also apply just fine to HEAD.
Comment #9
fmatias commentedI play a little with node_install_log_field_223820.patch and it seems OK.
Comment #10
gpk commentedI'm glad it worked, however I fear it may not be an appropriate fix in the long term - I've just discovered that default values for text fields are not good news (specifically, MySQL strict mode doesn't allow them - see e.g. http://drupal.org/node/201427#comment-678943).
So I think the correct fix would be to ensure that $node->log is always set before the node is saved. Since I've not reproduced the error on my own setup, it will be a bit tricky for me to track down the error at source and fix it. Hoping someone else will come along and advise/muck in ..!
Update: see also:
Adding NOT NULL columns with no default - http://drupal.org/node/159329
MySQL peculiarities with implicit defaults - http://drupal.org/node/159330
Comment #11
druus commentedJust wanted to confirm, patch also works here.
Comment #12
gábor hojtsyWe are not going to modify the database schema in Drupal 6 and in this case, it would not be a good solution anyway. We added code before to ensure that the log will be set. Look into node_save(), there is a huge code block just to ensure this:
Now it needs to be looked into, why this is not reached for you.
(Marking as no-patch, as the proposed patch was completely off).
Comment #13
damien tournoud commentedWhen editing a page for non-administrators, the book module force the saving of a revision in
nodeapi($op='presave'). In that case,$node->logis not set.The attached patch move the code highlighted in #12 by Gábor to
_node_save_revision(), and always adds$node->logwhen inserting a new revision.However, it feels like we should teach
drupal_write_record()to set default values to NOT NULL text fields when they are not set.Comment #14
gpk commentedMinor point - can I suggest changing
to
Comment #15
fmatias commentedFor the record, d6-core-book-empty-log.patch also works here.
Comment #16
catchBugs get fixed in 7.x then backported.
Comment #17
damien tournoud commentedHere is an updated patch, for D6 and D7, with minor changes to comments.
This bug basically breaks the book module for PostgreSQL users, and as such should get fixed as soon as possible.
Comment #18
damien tournoud commented#238388: Editing a book page by another user issues pgsql ERROR: null value in column "log" violates not-null was a duplicate.
Comment #19
floretan commentedTried on a fresh install with postgresql. I can't replicate the error message, but I do get the page not found with an alias (however, accessing the node with node/3 does work). I need to do more debugging and I don't want to mix other issues into this one, but it seems like there must be some issue with the path module also related to the original problem.
Comment #20
damien tournoud commentedHere is a test case for this bug.
It fails on my PostgreSQL 8.2 installation, but not on MySQL, as expected.
With the patch (reroll against HEAD included), all tests succeed.
PS: note that PostgreSQL tests currently return a lot of PHP exceptions because of an unrelated patch (http://drupal.org/node/256001).
Comment #21
damien tournoud commentedForget the patch (the test is still valid), I put together a more general solution in #261258: Fix node_save() insertion logic.
Comment #22
catchI think this should probably go in tests now.
Comment #23
damien tournoud commentedIn that case, we have a patch (tests-223820-core-book-empty-log.patch in #20).
Comment #24
catchStill applies with offset, we shouldn't concatenate prefixes onto randomName() though.
Comment #25
pwolanin commentedmarked http://drupal.org/node/424742 as a duplicate.
This looks pretty trivial to fix?
Comment #26
catchMoving this out of the critical bugs queue - see #607038: Meta issue: fix gaps in code coverage.
Comment #27
andypostIs patch for tests still needed? another issue already commited #261258: Fix node_save() insertion logic
Comment #29
joseph.olstadA lot of work went into psql for D7 in the past 24 months.
This has for sure been resolved in Drupal core 7.94, book tests are all passing green now. All tests green, have a look here:
PHP 8.2 & pgsql-13.5 2,110 pass tested on commit
Please upgrade your core to Drupal core 7.94.