Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Error message
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'nid' in where clause is ambiguous: SELECT DISTINCT node.title AS title FROM {node} node INNER JOIN {node_access} na ON na.nid = node.nid WHERE (nid = :db_condition_placeholder_0) AND(( (na.gid = :db_condition_placeholder_1) AND (na.realm = :db_condition_placeholder_2) )OR( (na.gid = :db_condition_placeholder_3) AND (na.realm = :db_condition_placeholder_4) )OR( (na.gid = :db_condition_placeholder_5) AND (na.realm = :db_condition_placeholder_6) ))AND (na.grant_view >= :db_condition_placeholder_7) ; Array ( [:db_condition_placeholder_0] => 5 [:db_condition_placeholder_1] => 0 [:db_condition_placeholder_2] => all [:db_condition_placeholder_3] => 0 [:db_condition_placeholder_4] => domain_site [:db_condition_placeholder_5] => 2 [:db_condition_placeholder_6] => domain_id [:db_condition_placeholder_7] => 1 ) in book_block_view() (line 287 of C:\xampp\uisd\modules\book\book.module).
I have DA enabled.
Created 2 test domains.
Created unique books for each domain. i.e books from one domain are not visible in another.
Enabled book navigation block.
Changed the block option to "Show block only on book pages".
Then got this error.
Comment | File | Size | Author |
---|---|---|---|
#39 | 1013864-book-fails-with-node-access-d8.patch | 602 bytes | hswong3i |
#36 | 1013864-book-fails-with-node-access-d7.patch | 602 bytes | hswong3i |
#30 | 1013864-book-fails-with-node-access.patch | 764 bytes | JimmyAx |
#17 | book.patch | 805 bytes | JimmyAx |
#13 | 1013864-book.patch | 946 bytes | agentrickard |
Comments
Comment #1
agentrickardThis is a bug in core Book module, which is not aliasing it's field correctly. This query is generated by the Drupal 'node_access' query tag.
Try the attached.
Comment #2
agentrickardBetter title.
Comment #4
agentrickardThose test fails are totally unrelated to this patch.
Comment #5
mr.baileysProbably needs a test too...
Comment #6
agentrickardBy that standard, any node select query in core needs a test with node access turned on.
Comment #7
Mo CreditAttribution: Mo commentedWhen I applied the above patch, I got this error.
Comment #8
Mo CreditAttribution: Mo commentedComment #9
Mo CreditAttribution: Mo commented#1: 1013864-book.patch queued for re-testing.
Comment #10
Mo CreditAttribution: Mo commentedI think I fixed it. I don't know how to create a patch. But this is what I did after applying the patch.
$select->addField('n', 'node', 'title');
to
$select->addField('n', 'title');
Comment #11
agentrickard@Mo:
That's actually confusing this issue, sorry. There are two things happening here.
Your original post is a query alter run by the Node module, which is a core bug.
The second post (in #7) is the implementation of domain_node_access_query_alter(), which is a different issue and would need to be altered after the core patch lands.
For right now, we have to fix #1 first, in core.
Comment #12
agentrickardSetting proper status.
@Mo: http://drupal.org/patch/create Where did you make that edit?
Comment #13
agentrickardFound the change. Let's just make this query syntax match that from node_page_default().
@Mo -- for core, you can only set a patch file to 'needs review'.
Comment #14
Mo CreditAttribution: Mo commentedOh! I didn't mean to change the status. I guess I just hit submit without looking at the status field while commenting.. hehe I'm still a newbie. :D
Comment #15
agentrickardNot a problem. "Needs review" sends the latest patch to the automated testing system.
Comment #16
Jody LynnComment #17
JimmyAx CreditAttribution: JimmyAx commentedThis patch worked great for me and is very clean.
Comment #18
mariusz.slonina CreditAttribution: mariusz.slonina commentedRTBC++
Comment #19
yukare CreditAttribution: yukare commentedThe path at #17 woks for me
Comment #20
nijadzak CreditAttribution: nijadzak commented#17 worked for me
Comment #21
BarwonHack CreditAttribution: BarwonHack commentedYep #17 is a winner. Thanks JimmyAx.
Comment #22
eric.chenchao CreditAttribution: eric.chenchao commentedsubscribe
Comment #23
goshangai CreditAttribution: goshangai commented#1: 1013864-book.patch queued for re-testing.
Comment #24
catchComment #25
hswong3i CreditAttribution: hswong3i commentedsubscribe
Comment #26
Dries CreditAttribution: Dries commentedI committed the patch in #13 to 7.x and 8.x. The patch in #17 looked good too, but is less consistent with the rest of core. Thanks!
Comment #27
Anonymous (not verified) CreditAttribution: Anonymous commented@Dries: that fix from #13 has problems. Please see #1109852: Ambiguous column name from db_select()->fetchField and #589552: Drupal 7 version of Support Ticketing System
The fix should be change this:
to this
Best regards!
Comment #28
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #29
catchWill need to go into 8 first.
Comment #30
JimmyAx CreditAttribution: JimmyAx commentedAttaching patch.
Comment #31
JimmyAx CreditAttribution: JimmyAx commentedAnd we probably need it to be reviewed...
Comment #32
agentrickardFair enough. (I wrote #13 and was a bit confused by alias usage in DBTNG.
Comment #33
webchickOK, we already committed one fix without tests, and doing this caused more brokenage. So this time, we need tests.
There's a node_access_test.module you may be able to enable in setUp() in order to to trigger the error, not sure...
Comment #34
sunThe remaining bug in this issue might be annoying (when using certain contrib modules), but it's no longer major.
Comment #35
AdamGS CreditAttribution: AdamGS commentedsubscribe
Comment #36
hswong3i CreditAttribution: hswong3i commentedI just check with latest Drupal 7.4 but fond that this bug still exists. Here is the rework version for drupal-7.x GIT.
Tested with node_access and all works fine.
Comment #37
yukare CreditAttribution: yukare commentedI have the same issue in drupal 7.4, and the patch at #36 fixes it using acl + content access
Comment #38
catchPlease don't change version numbers, we fix in the highest affected version then backport.
Comment #39
hswong3i CreditAttribution: hswong3i commentedPatch via drupal-8.x-dev GIT.
Comment #40
catchThis is a duplicate of #766382: Column 'nid' is ambiguous when using node access modules which has /exactly/ the same patch on it.