Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
When Drupal is installed, node_install() creates a record in the node_access table with nid = 0. Zero is not a valid value for nid and violates the foreign key constraint declared in node_schema(). The default should be stored some other way or a default node with nid = 0 should be added to the node table.
Comment | File | Size | Author |
---|---|---|---|
#20 | 1703222.patch | 698 bytes | catch |
#1 | 1703222-node-access-record-that-violates-constraint.patch | 634 bytes | nick_schuch |
Comments
Comment #1
nick_schuch CreditAttribution: nick_schuch commentedFirst attempt.
Comment #2
nick_schuch CreditAttribution: nick_schuch commentedComment #4
marcingy CreditAttribution: marcingy commentedDrupal core does not actually use foreign keys internally - this issues seems like a won't fix to me.
Comment #5
Liam MorlandOne solution would be to remove the foreign key constraint declared in node_schema(). Whether or not foreign key constraints are created in the database, it is wrong to declare that a constraint exists if the code is not following it.
What is the record in the node_access table with nid = 0 used for? If it stores defaults, can these be stored some other way?
Comment #6
Damien Tournoud CreditAttribution: Damien Tournoud commentedThe obvious way of fixing this would be to change the access record to use NULL as the nid (and change the definition of the column if it is not nullable). This is the intend of the code.
Comment #7
Liam Morlandnid can't be null; it's part of the primary key.
Comment #8
Liam MorlandIs the record with nid=0 ever updated? If not, the default values can be in the code instead of in the database.
Comment #9
webchickI'd need to refresh my memory on exactly how, but yes, that database row is special. It's something like "If it's there, we don't have node access, so do things the fast way" and "If it's not, then engage the node grants system."
Comment #10
Liam MorlandFrom the documentation for node_access_view_all_nodes():
Later, a comment says "If no modules implement the node access system, access is always TRUE.", which sounds like the opposite of what you said: The row is only looked at if module_implements('node_grants') != TRUE.
In any case, what I said in #8 is key. There is no point putting static data in the database.
Comment #11
xjm(Merging "node system" and "node.module" components for 8.x; disregard.)
Comment #20
catchLet's see.