I am posting this in the general forum since I have no clue where this might be coming from.

Since yesterday all users who are not admin get the following error message when they are trying to access certain pages on the site (Drupal 7.8 - no certain pattern visible):

"Exception: Query tagged for node access but there is no nid. Add foreign keys to node.nid in schema to fix. in _node_query_node_access_alter() (line 3218 of ...\modules\node\node.module)."

I'd really appreciate if someone could point me to the direction where I should start looking to solve the problem.

Thanks a lot in advance!


BeaPower’s picture

I get this too, any fix?

neilolsen’s picture

I am getting this too. Anyone can help?

chemicalroman’s picture

I also have the same problem when an anonymous user tries to see user profiles.

neilolsen’s picture

I did some test and found out that adding User: Content Authored Relationship in my Views caused this, in my case.
I dont have the solution yet ... just highlighting the possible cause.

NB: I am Drupal newbie and not a web programmer btw. :)

prodigeek’s picture

Same issue. Though mine seems caused by Taxonomy relationships. (I have parent and terms used on content). Only affects anonymous users.

Thank you.

prima.werefox’s picture

I had same problem when tried to access to view from anonymous user. View has taxonomy terms with contents count by term.
I resolved this error by disable rewriting query for this view

chemicalroman’s picture

I can confirm that disabling SQL rewriting of that view worked.

ymeiner’s picture

The fact that we can work around the issue does not mean that it is solved. it involves views with file references and access to the files if you are not admin.

hope that we can find a better solution than bypassing views permissions.

prima.werefox’s picture

Problem arise when in query actually no nodes table can be found but node access check must be done. Essentially there is two solution on current database - insert node table on query rewrite and simply bypass access rights on this types of queries.
I don't want to write any patch because this is core functionality and more political decision than technical.

Jaapx’s picture

I have a use case where it's important that the query can access en present content to users that do not have otherwise access. Maybe the best solution is a choice for the query writer without the programcrash.

liquidcms’s picture

i agree disabling access control is the wrong answer; but i can confirm that it seems to be a combination of:

- user view
- relationship defined
- rewrite sql enabled

also, it seems even if the view doesn't display on that page (for instance because it is empty); the error still occurs.

i have posted the issue here: #1326252: sql rewrite casues exception error for user views with relationships defined

Pipolaye’s picture

Hello guys, I have the following error with 5 nodes (out of 50 nodes) with some roles:

Exception: Query tagged for node access but there is no nid. Add foreign keys to node.nid in schema to fix.

Where should I look / whatshould I do to fix this issue? I tried to clone the node, I still have the same error. If I create a new node though, everything works fine.

Thank you for your help!