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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

agentrickard’s picture

Project: Domain » Drupal core
Version: 7.x-2.6 » 7.0-rc4
Component: Code » block.module
Status: Active » Needs review
Issue tags: +DBTNG Conversion
FileSize
919 bytes

This 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.

agentrickard’s picture

Title: Books module Navigation Block » Book navigation block fails with Node Access modules

Better title.

Status: Needs review » Needs work

The last submitted patch, 1013864-book.patch, failed testing.

agentrickard’s picture

Those test fails are totally unrelated to this patch.

mr.baileys’s picture

Component: block.module » book.module

Probably needs a test too...

agentrickard’s picture

By that standard, any node select query in core needs a test with node access turned on.

Mo’s picture

When I applied the above patch, I got this error.

Error message
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'n.node' in 'field list': SELECT DISTINCT n.node AS title FROM {node} n INNER JOIN {domain_access} da_admin ON da_admin.nid = n.nid WHERE (n.nid = :db_condition_placeholder_0) AND(( (da_admin.gid = :db_condition_placeholder_1) AND (da_admin.realm = :db_condition_placeholder_2) )OR( (da_admin.gid = :db_condition_placeholder_3) AND (da_admin.realm = :db_condition_placeholder_4) )); Array ( [:db_condition_placeholder_0] => 4 [:db_condition_placeholder_1] => 0 [:db_condition_placeholder_2] => domain_site [:db_condition_placeholder_3] => 3 [:db_condition_placeholder_4] => domain_id ) in book_block_view() (line 287 of C:\xampp\uisd\modules\book\book.module).
Mo’s picture

Version: 7.0-rc4 » 7.0
Mo’s picture

Status: Needs work » Needs review

#1: 1013864-book.patch queued for re-testing.

Mo’s picture

I 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');

agentrickard’s picture

@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.

agentrickard’s picture

Status: Needs review » Needs work

Setting proper status.

@Mo: http://drupal.org/patch/create Where did you make that edit?

agentrickard’s picture

Status: Needs work » Needs review
FileSize
946 bytes

Found 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'.

Mo’s picture

Oh! 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

agentrickard’s picture

Not a problem. "Needs review" sends the latest patch to the automated testing system.

Jody Lynn’s picture

Version: 7.0 » 7.x-dev
JimmyAx’s picture

FileSize
805 bytes

This patch worked great for me and is very clean.

mariusz.slonina’s picture

RTBC++

yukare’s picture

Status: Needs review » Reviewed & tested by the community

The path at #17 woks for me

nijadzak’s picture

#17 worked for me

BarwonHack’s picture

Yep #17 is a winner. Thanks JimmyAx.

eric.chenchao’s picture

subscribe

goshangai’s picture

#1: 1013864-book.patch queued for re-testing.

catch’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D7
hswong3i’s picture

subscribe

Dries’s picture

Status: Reviewed & tested by the community » Fixed

I 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!

Anonymous’s picture

@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:

    ->condition('nid', $node->book['bid'])

to this

    ->condition('n.nid', $node->book['bid'])

Best regards!

Anonymous’s picture

Version: 8.x-dev » 7.x-dev
Status: Fixed » Active
catch’s picture

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

Will need to go into 8 first.

JimmyAx’s picture

Attaching patch.

JimmyAx’s picture

Status: Active » Needs review

And we probably need it to be reviewed...

agentrickard’s picture

Status: Needs review » Reviewed & tested by the community

Fair enough. (I wrote #13 and was a bit confused by alias usage in DBTNG.

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

OK, 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...

sun’s picture

Priority: Major » Normal

The remaining bug in this issue might be annoying (when using certain contrib modules), but it's no longer major.

AdamGS’s picture

subscribe

hswong3i’s picture

Version: 8.x-dev » 7.x-dev
Status: Needs work » Needs review
FileSize
602 bytes

I 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.

yukare’s picture

I have the same issue in drupal 7.4, and the patch at #36 fixes it using acl + content access

catch’s picture

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

Please don't change version numbers, we fix in the highest affected version then backport.

hswong3i’s picture

Patch via drupal-8.x-dev GIT.

catch’s picture

Status: Needs review » Closed (duplicate)

This is a duplicate of #766382: Column 'nid' is ambiguous when using node access modules which has /exactly/ the same patch on it.