Hi
I got an error on the User page:
user warning: Unknown column 'n.nid' in 'on clause' query: SELECT DISTINCT(type) FROM content_complete INNER JOIN node_access na ON na.nid = n.nid WHERE (na.grant_view >= 1 AND ((na.gid = 0 AND na.realm = 'all') OR (na.gid = 2 AND na.realm = 'nodeaccess_rid') OR (na.gid = 4 AND na.realm = 'nodeaccess_rid') OR (na.gid = 3 AND na.realm = 'nodeaccess_uid') OR (na.gid = 3 AND na.realm = 'nodeaccess_author') OR (na.gid = 3 AND na.realm = 'user_relationship_node_access_author') OR (na.gid = 2 AND na.realm = 'workflow_access') OR (na.gid = 4 AND na.realm = 'workflow_access') OR (na.gid = 3 AND na.realm = 'workflow_access_owner'))) in /var/www/servers/version2/sites/all/modules/content_complete/content_complete.module on line 307.

Comments

bennos’s picture

Status: Active » Fixed

applied the patch http://drupal.org/node/363242 and error disappears.

alex.k’s picture

Status: Fixed » Postponed (maintainer needs more info)

Sounds like either user_relationship_node_access or workflow is not rewriting SQL correctly, as the patch references removes db_rewrite_sql()... It would help if you tried original code and alternatively disabled either of both modules, to see when the error goes away.

jcmarco’s picture

I found the same bug, and I was disabling one by one the modules that have some access realm in the sql error.

After that, I was reading the Drupal API documentation, http://api.drupal.org/api/function/db_rewrite_sql/6.

And I don't see any need to check any right when accessing to the content_complete, as there is no any primary key associated between this content_complete table and any node id, as come by default in the db_rewrite_sql the primary key:

db_rewrite_sql($query, $primary_table = 'n', $primary_field = 'nid', $args = array())

$primary_table Name or alias of the table which has the primary key field for this query. Typical table names would be: {blocks}, {comments}, {forum}, {node}, {menu}, {term_data} or {vocabulary}. However, it is more common to use the the usual table aliases: b, c, f, n, m, t or v.

So IMHO this security check functionally has no meaning as there is no relationship between content_complete and node id's or any existing typical table.

jcmarco’s picture

StatusFileSize
new1.5 KB

I add a patch for removing the db_rewrite_sql

pvhee’s picture

I guess you're right when it comes to the {content_complete} table. However, when doing queries on node tables I think you should use db_rewrite_sql:

$sql = "SELECT * FROM {node} WHERE type = '%s'";
$result = db_query(db_rewrite_sql($sql), $content_type);

Am I correct? I would like to clarify this before committing any patches.

avpaderno’s picture

Status: Needs work » Postponed (maintainer needs more info)

Of the query the patch changes, only the last two should be corrected.
db_rewrite_sql() is normally used from code that wants to have a list of nodes, users. Using that function allows other modules to add a more restrictive filter on the returned list; that what happened for a Drupal core module that filters out the nodes to which the current user doesn't have access.

pvhee’s picture

I removed db_rewrite_sql from the content_complete tables. Latest version on CVS.

avpaderno’s picture

Status: Postponed (maintainer needs more info) » Needs work

@pvhee: a module can call db_rewrite_sql() for its own database tables too; it has sense to do so if there is a module that can modify the SQL queries made from that module.

avpaderno’s picture

Status: Postponed (maintainer needs more info) » Fixed

Whoops; this is called concurrent editing.
The issue should then be considered fixed.

jcmarco’s picture

Status: Fixed » Needs review
StatusFileSize
new1.24 KB

Testing again.

With Content Profile, and Content Complete configured using the APK's uprofile content type.

With a registered user with standard permissions, (not admin, but can create content profile).

If the user has or not content profile created (never has completed any field in the form) in both cases then I have the ugly sql error in line 223.

If I remove the db_rewrite from this line then the error vanish, working everything fine, if there is no any content profile then there is no errors and no completion bar, but if there is a content complete it shows the progression bar, so good.

So there was something wrong in the db_rewrite_sql to line 223

Reading http://drupal.org/node/324070#comment-1073102, I realize that the problem is not using a distinct selection and that is needed FROM {node} n, when using db_rewrite_sql(), so just changing the $sql statements in the three queries using db_rewrite_sql (), everything works great, with no errors and with security validation.

pvhee’s picture

StatusFileSize
new1.55 KB

Thanks, this might solve the problem indeed. I slightly modified the patch to select node id's only (as thats the only thing we need).

Can you check if the patch solves the problem? If so I will commit it to CVS.

jcmarco’s picture

It works great, you also solved the other question regarding not to do "select * from", because possible performance problems.

pvhee’s picture

Status: Needs review » Fixed

Patch committed. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.