5

When you view this question you see a closed question which has an accepted answer.

When you get the API info for it you get this:

["question_id"]=>
int(17466804)
["creation_date"]=>
int(1372930412)
["score"]=>
int(-4)
["closed_date"]=>
int(1372932196)
["title"]=>
string(29) "convert flat text file to pdf"
["closed_reason"]=>
string(9) "off-topic"
["link"]=>
string(73) "https://stackoverflow.com/questions/17466804/convert-flat-text-file-to-pdf"
["is_answered"]=>
bool(false)
["close_vote_count"]=>
int(0)
["reopen_vote_count"]=>
int(0)
["delete_vote_count"]=>
int(0)

The field is_answered is returning false even though the question has not only an answer, but an accepted one.

I thought it might have to do with the question being closed. However, other closed questions which also have an accepted answer correctly return true. For example, this question.

The other reason could be the negative score for the answer. But it should not effect the field since even a negative score answer can end up being correct. If this is intended behavior it should be documented on the question doc page.

2 Answers 2

3

Update: Per Kevin Montrose's answer and its comments:

The bug has now been fixed and the is_answered property will return true if either of these is true:

  • The question has an accepted answer
  • The question has an answer with a score > 0

To detect just whether a question has an accepted answer, merely check that the accepted_answer_id property is present and has an integer value



This looks like a bug rather than (just) a documentation error. The is_answered property should mirror the hasaccepted search key. (See Advanced Search Tips on the Search page.)

If we search for hasaccepted:yes, the question shows up.
Screenshot in case the Q is deleted (Click for larger image) : Search results

The Help Center makes no mentions that answers don't count if they have negative scores.

Likewise, I could find nothing on Meta (so far) that says that some "answered" questions don't count as answered.

Note that the API returns is_answered is false, but the question also has an accepted_answer_id. So that seems like a contradiction right there.

Also, the API's /search/advanced path, with accepted=True returns the question, as expected.

4

Tricky.

This was a consequence of the API misinterpreting a normalized field used elsewhere in the system to indicate whether or not a post has upvoted answers.

Everywhere else, "is answered" is true if either of the following are met:

  • The question has an accepted answer
  • The question has an answer with a score > 0

The API wasn't doing the "or" check.

This was fixed in the last deploy.

2
  • So, to be clear, to mimic the useful hasaccepted search, we must check the API results to see if the accepted_answer_id property is present.?. The is_answered property is now = ({has accepted ans} OR {has upvoted ans}).?. Also is it upvoted answer or answer with a positive score? Commented Jul 17, 2013 at 22:06
  • @BrockAdams with a score > 0 ; is_answered should be set if either there is an accepted answer, or their is a > 0 score answer. hasaccepted is just checking accepted_answer_id. Commented Jul 17, 2013 at 23:21

You must log in to answer this question.

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