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.

Replace_more() AssertionError After Refreshing Comment

See original GitHub issue

Describe the bug

Using the replace_more() function on a comment’s replies after the comment has been refreshed raises an AssertionError. This only happens on certain submissions and I’m not sure why (the code below is an example of a submission that fails). Also, the AssertionError is not raised if the refresh() function is not called on the comment.

To Reproduce Run this code after replacing your client_id, client_secret, and user_agent.

import praw

reddit = praw.Reddit(
    client_id="YOUR-CLIENT-ID",
    client_secret="YOUR-CLIENT-SECRET",
    user_agent="YOUR-USER-AGENT",
)

submission = reddit.submission(id="6aeian")

submission.comment_sort = "confidence"
submission.comments.replace_more()
comments = submission.comments.list()

for comment in comments:
    comment.reply_sort = "confidence"
    comment.refresh()

    # Errors on line below
    comment.replies.replace_more()

Expected behavior

I expected this to run without raising any exceptions.

Code/Logs

Traceback (most recent call last):
  File "/mnt/c/Users/<NAME>/Documents/GitHub/Reddit-Bot/test_praw.py", line 19, in <module>
    comment.replies.replace_more()
  File "/mnt/c/Users/<NAME>/Documents/GitHub/Reddit-Bot/Reddit-Bot/lib/python3.6/site-packages/praw/models/comment_forest.py", line 177, in replace_more
    self._insert_comment(comment)
  File "/mnt/c/Users/<NAME>/Documents/GitHub/Reddit-Bot/Reddit-Bot/lib/python3.6/site-packages/praw/models/comment_forest.py", line 69, in _insert_comment
    assert comment.name not in self._submission._comments_by_id
AssertionError

System Info

  • OS: WSL running Ubuntu 18.04.3 LTS
  • Python: 3.6.9
  • PRAW Version: 6.4.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
PythonCoderAScommented, Jan 7, 2020

Replace_more is destructive, so why not create a new Comment and then replace_more that? You can make it a function.

def get_morecomment_count(forest):
    morecount = 0
    for comment in forest:
        if isinstance(comment, MoreComments):
            morecount += 1
submission.comments.replace_more(limit=get_morecomment_count(submission.comments))
comment = submission.comments[0] # example comment
new_comment = reddit.comment(id=comment.id)
comment.replies.replace_more(limit=get_morecomment_count(comment.replies))
0reactions
PythonCoderAScommented, Jan 9, 2020

@tchanxx your error is calling both submission.comments.replace_more() and comment.replies.replace_more(). Since they share the same root submission, this caused the error. If you need to retrieve replies, create a new instance of a comment through the reddit instance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IntellIj 2018.3 java.lang.AssertionError when refresh gradle ...
In my project, when I run gradle build, I have an error message related ... I was able to comment out the following...
Read more >
Python Tutorial - Getting Started with Python and Python Basics
This section is for experienced programmers to look at Python's syntaxes and those who need to refresh their memory. For novices, go to...
Read more >
Comments are not automatically updated once they are posted
Issue Summary. After updating the JIRA application to version 9.0.0, The comments are not updated once they are published. Steps to Reproduce.
Read more >
Python's assert: Debug and Test Your Code Like a Pro
The advantage of an assert statement over a comment is that when the condition isn't true, assert immediately raises an AssertionError . After...
Read more >
Assertion Error when upgrading from Drupal 8.9.14 to 9.1.7
Problem/Motivation I am getting an Assertion Error when upgrading a site from Drupal 8.9.14 to 9.1.7. ... Jump to comment: Most recent ...
Read more >

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