8

We're seeing that, when a particular filter we've created is used, the API will return "comment_count": 1 for questions with no comments.

For a search for questions with no answers, ordered by descending creation date, with our filter applied: Many questions with no comments are returned with "comment_count": 1.


Here's the response for question ID 28269098, with comment_count added to the default filter. It correctly returned "comment_count": 0 (back when the question didn't have any comments):

{
  "items": [
    {
      ...
      "comment_count": 0,
      ...
      "question_id": 28269098,
      "link": "http://stackoverflow.com/questions/28269098/resize-uibuttons-iphone-5-to-iphone-6-ratio",
      "title": "Resize UIButtons iPhone 5 to iPhone 6 ratio"
    }


But here's the response for question ID 28269098, with our problem filter applied, which incorrectly returns "comment_count": 1 for the same question:

{
  "items": [
    {
      ...
      "comment_count": 1,
      ...
      "question_id": 28269098,
      "link": "http://stackoverflow.com/questions/28269098/resize-uibuttons-iphone-5-to-iphone-6-ratio",
      "title": "Resize UIButtons iPhone 5 to iPhone 6 ratio"
    }

(Editor's note. Now that that question has comments (currently 3), the OP's query returns the correct number. But I have confirmed this bug on posts with no comments.)

Why is comment_count returning an invalid value, for comment-less posts, when we use our filter?

2
  • 1
    I can confirm that this behaviour still exists in the current API version. I've noticed the wrong comment_count value of 1 as well on quite a lot of questions without comments.
    – Oldskool
    Aug 26, 2016 at 8:09
  • Bug still exists even now :/ Mar 20, 2019 at 18:48

1 Answer 1

5

Confirmed the bug on a post that accrues comments much slower than a typical Stack Overflow question does.

Currently, the OP's filter returns "comment_count": 1 on that post. There are no comments.

I believe this is a side-effect/bug/quirk with how the API appears to be counting the comments. ¿Perhaps it is counting Ids in the comment table and not properly coalescing a null (or properly forming the join) when comments are turned off by the filter?

Anyway, altering the OP's filter by:

  • selecting comment.comment_id
  • and selecting question.comments

As seen in this query, works-around the problem. It currently returns "comment_count": 0 (Correct) for that question.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .