question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AssertionError: comment.parent_id in self._submission._comments_by_id

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:25 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
PythonCoderAScommented, Apr 26, 2020

@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?

0reactions
tryashtarcommented, Oct 14, 2021

Thanks so much! 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found