Repository: praw-dev/praw

Issue:
Comment.replies always gives empty list
For the last day or so I've noticed this. Not sure if reddit changed something?



Discussion:
I'm working on this.

I'm still getting an empty list until I call `Comment.refresh()`. Am I supposed to have to call that function for every comment?

You shouldn't have to call that every time. Could you post a snippet of
code that demonstrates the bug?

In my case I'm simply getting a single comment from the reported queue of a subreddit that I know has replies. 

When you fetch a comment anywhere other than from a submission location it should never had replies associated with it. However, PRAW _should_ be smart enough to know that replies have yet been fetched, and then go about fetching them. There's likely something still broken in the "replies have yet to be fetched" logic.

> PRAW should be smart enough to know that replies have yet been fetched

Agreed. I don't know why this suddenly stopped working though, I never had any issues until recently.

It's likely that the JSON on reddit's end changed from returning a None like value to an empty string. Worse, maybe they now return an empty array. If this affects you directly, you're probably the best person to fix it :).

I'm having the same issue atm. My solution is calling .refresh() every time I need to look at the replies.

I'm going to start working on fixing this bug.

> I'm going to start working on fixing this bug.

Awesome @superman3275!

Any status @superman3275?

Labeled as "unconfirmed bug" until either myself or @voussoir verifies the issue and updates the label. What would help is providing a few repeatable lines of code necessary to observe the issue.

I haven't been able to observe the issue on my machine, I've made some changes which I thought should fix the issue, but they seem to have no effect. Still digging around.

It'd be much easier for me if someone provided a couple lines of code demonstrating the issue, ideally in a sandbox environment like a custom subreddit.

I have this issue when getting comments using `praw.helpers.comment_stream` / `praw.objects.Subreddit.get_comments`. 

Here is a few lines of code that use a custom subreddit:

```
>>> import praw
>>> r = praw.Reddit("PRAW bug confirmation")
>>> for c in praw.helpers.comment_stream(r, 'WPC_CssTest'):
...     print c.body, len(c.replies)
...
Test 0: 3 (2.42 ips)
comment1 0
comment2 0
Traceback (most recent call last):
```

(comment1 is the parent of comment2, so it should print `comment1 1`

It's easy to reproduce (it will print an empty list then a list with the correct number of replies)

``` python
r = praw.Reddit(user_agent="test issue")
user = r.get_redditor(<name here>)

for c in user.get_comments():
    print(c.replies) 
    c.refresh()                                                            
    print(c.replies)   
```

@kviktor @roger- @eleweek @undercase 

The issue is moreso with reddit, and not PRAW. If you would look at [this JSON](https://thepb.in/55d65c52b8cad4.txt), you will see that the `replies` key is `""`, i. e. empty, So PRAW returns as such for the attribute. 

**However**:

The [JSON](https://thepb.in/55d65d5f747240.txt) of a comment's permalink **does** have the `replies` key. 

Considering this, natively, fixing this plainly through API would be impossible due to the fact that the API itself is not giving a dict of replies, and, to be fair, it's expected due to the nature of the /u/me/comments page, you simply can't see replies to comments.

**But**, as I was already going to add multiple methods in relation to comments, I'll implement a workaround that's fairly simple, which would be to request the permalink of the comment and pass that through the json objector instead and get the `replies` attribute. Unfortunately, this causes PRAW to make 2 requests (IIRC), instead of one, which may not be ideal.


Resolving patch:
diff --git a/praw/objects.py b/praw/objects.py
--- a/praw/objects.py
+++ b/praw/objects.py
@@ -652,7 +652,14 @@ def permalink(self):
 
     @property
     def replies(self):
-        """Return a list of the comment replies to this comment."""
+        """Return a list of the comment replies to this comment.
+
+        If the comment is not from a submission, :meth:`replies` will
+        always be an empty list unless you call :meth:`refresh()
+        before calling :meth:`replies` due to a limitation in
+        reddit's API.
+
+        """
         if self._replies is None or not self._has_fetched_replies:
             response = self.reddit_session.request_json(self._fast_permalink)
             if not response[1]['data']['children']:


Test patch: