Replace_more() AssertionError After Refreshing Comment
See original GitHub issueDescribe 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:
- Created 4 years ago
- Comments:13 (10 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Replace_more is destructive, so why not create a new Comment and then replace_more that? You can make it a function.
@tchanxx your error is calling both
submission.comments.replace_more()
andcomment.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.