praw: AssertionError: comment.parent_id in self._submission._comments_by_id

Describe the bug When loading all the comments for post 41ntws (and a handful of others), I get this assertion error. I have not had this problem on tons of other posts, just a few. In case it’s helpful, here is the complete list of posts I get this error on:

50slvn
4wvz6z
4fmyzj
41ntws
41dkav
3gljgr
a8ekca
fz5363

They’re all AskReddit posts with pretty high comment counts, but I’ve downloaded posts with even more comments regularly before with no issue.

I found that it seems to be breaking when it gets to comment cz3wnj7. Interestingly, going to the parent of that comment gives a weird “there doesn’t seem to be anything here” page instead of showing a deleted comment like normal. That probably has something to do with it.

To Reproduce Steps to reproduce the behavior:

  1. Fetch the post with ID 41ntws
  2. Do comments.replace_more(limit=None)
  3. Wait

Expected behavior All comments get loaded

Code/Logs Here is my exact repro code:

import praw
import json

credentials = json.load(open("D:/~No Sync/reddit auth.json"))
reddit = praw.Reddit(client_id=credentials['client_id'], client_secret=credentials['client_secret'], user_agent=credentials['user_agent'], username=credentials['username'], password=credentials['password'])
post = reddit.submission(url="https://reddit.com/comments/41ntws")
post.comments.replace_more(limit=None)

Here is my stacktrace:

Traceback (most recent call last):
  File "D:\Documents\Website Archive\code\test.py", line 7, in <module>
    post.comments.replace_more(limit=None)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\praw\models\comment_forest.py", line 194, in replace_more
    self._insert_comment(comment)
  File "C:\Program Files (x86)\Python38-32\lib\site-packages\praw\models\comment_forest.py", line 82, in _insert_comment
    assert comment.parent_id in self._submission._comments_by_id, (
AssertionError: PRAW Error occured. Please file a bug report and include the code that caused the error.

System Info

  • OS: Windows 10
  • Python: 3.8.2
  • PRAW Version: 7.0.0

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 25 (13 by maintainers)

Most upvoted comments

@tryashtar I have a test version with your fix. I’m not getting the same error as you because in my preferences, I have comments expand to the maximum length, which might bypass the error. Can you run pip install git+https://github.com/praw-dev/praw.git@no-assertionerror and then try the code again?