When I allow anonymous users to view comments I receive following error:

PDOException: SQLSTATE[HY000]: General error: 1 near "0": syntax error: SELECT thread.thread AS thread_thread FROM (SELECT comment.thread AS thread FROM {comment} comment WHERE (nid = :db_condition_placeholder_0) AND (status = :db_condition_placeholder_1) ORDER BY created DESC, cid DESC LIMIT OFFSET 0) thread ORDER BY SUBSTRING(thread, 1, (LENGTH(thread) - 1)) ASC LIMIT 1 OFFSET 0; Array ( [:db_condition_placeholder_0] => 82 [:db_condition_placeholder_1] => 1 ) in comment_new_page_count() (line 547 of /var/www/d7.dyzio/htdocs/modules/comment/comment.module).
The website encountered an unexpected error. Please try again later.

I'm using D7-alpha5 on sqlite, comments and article nodes generated with Devel module (default settings).

When I disable threaded comments, the problem not occur.

CommentFileSizeAuthor
#8 comment_anonymous_thread.patch501 bytesmariusz.slonina

Comments

mariusz.slonina’s picture

Maybe

comment.thread AS thread FROM {comment}

instead of

comment.thread AS thread FROM {comment} comment

?

damien tournoud’s picture

The problem is in the subquery:

SELECT comment.thread AS thread FROM {comment} comment WHERE (nid = :db_condition_placeholder_0) AND (status = :db_condition_placeholder_1) ORDER BY created DESC, cid DESC LIMIT OFFSET 0

That should be LIMIT $new_replies OFFSET 0.

But that's really weird, because comment_new_page_count() should never be called with an empty $new_replies.

mariusz.slonina’s picture

When I do dummy rewrite, the problem is gone, I'm sure it can be done much better

   // Threaded comments: we build a query with a subquery to find the first
    // thread with a new comment.

    // 1. Find all the threads with a new comment.
    if ($new_replies) {
      $unread_threads_query = db_select('comment')
        ->fields('comment', array('thread'))
        ->condition('nid', $node->nid)
        ->condition('status', COMMENT_PUBLISHED)
        ->orderBy('created', 'DESC')
        ->orderBy('cid', 'DESC')
        ->range(0, $new_replies);
    } else {
      $unread_threads_query = db_select('comment')
        ->fields('comment', array('thread'))
        ->condition('nid', $node->nid)
        ->condition('status', COMMENT_PUBLISHED)
        ->orderBy('created', 'DESC')
        ->orderBy('cid', 'DESC');
    }
damien tournoud’s picture

@mariusz.slonina: there are only two places in core where we call comment_new_page_count(), and both of them have a check on $new_replies before calling the function.

Can you check from where this function is called from your installation?

mariusz.slonina’s picture

Comment_node_view on teaser, but that strange, beacuse comment_num_new should return FALSE on anonymous and function shouldn't be called

mariusz.slonina’s picture

I have Forum module disabled

mariusz.slonina’s picture

try this (in comment_node_view):

$new =  comment_num_new($node->nid);
//if (!$new) { // FALSE converted to TRUE for anonymous users
          if ($new) {
mariusz.slonina’s picture

Status: Active » Needs review
StatusFileSize
new501 bytes

Attaching a patch

mariusz.slonina’s picture

Status: Needs review » Fixed

Seems to be included in d7-beta1, thanks :)

Status: Fixed » Closed (fixed)

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