steem.blog.take() should return top-level posts for Blog(comments_only=False) and comments for Blog(comments_only=True). The distinction between post and comment internally uses steem.utils.is_comment(). This should returns False for root posts, True or others for comments.
Actual Behavior
steem.utils.is_comment() returns False if the post is a comment but the permlink doesn't start with "re-". As a result, the Blog().take() results may be lacking comments or list comments as root posts.
Steps to reproduce
Reply to a post with a custom permlink that doesn't start with "re-".
>>> from steem.post import Post
>>> from steem.utils import is_comment
>>> is_comment(Post("stmdev/steem-utils-is-comment-root-post"))
False
>>> is_comment(Post("stmdev/re-steem-utils-is-comment-root-post-20180427t113939"))
'stmdev'
>>> is_comment(Post("stmdev/lorem-ipsum-dolor-sit-amet"))
False
steem.utils.is_comment is used in steem.blog.take() and therefore possibly returns wrong results for Blog(comments_only=True) and Blog(comments_only=False):
>>> from steem.blog import Blog
>>> b = Blog("stmdev", comments_only=False)
>>> b.take(5)
[<Post-stmdev/utils-iscomment-should-not-rely-on-re-in-permlink>, <Post-stmdev/lorem-ipsum-dolor-sit-amet>, <Post-stmdev/steem-utils-is-comment-root-post>, <Post-stmdev/difftest>, <Post-stmdev/clicking-tag-in-body-exceeding-1169-chars-triggers-a-502-bad-gateway>]
The second result in this example is actually a comment.
Stack Trace
none.
Possible fixes:
diff --git a/steem/utils.py b/steem/utils.py
index 856ebb8..8842fef 100755
--- a/steem/utils.py
+++ b/steem/utils.py
@@ -186,7 +186,7 @@ def is_comment(item):
The item can be a Post object or just a raw comment object from the
blockchain.
"""
- return item['permlink'][:3] == "re-" and item['parent_author']
+ return item['parent_author'] != ""
def time_elapsed(posting_time):
This would also avoid the inconsistency of returning False for root posts but the parent author as string for comments.
Alternatively: remove steem.utils.is_comment() and use steem.post.is_comment() instead?
Version of Python you are running
Version of steem-python you are running
Expected Behavior
steem.blog.take()
should return top-level posts forBlog(comments_only=False)
and comments forBlog(comments_only=True)
. The distinction between post and comment internally usessteem.utils.is_comment()
. This should returnsFalse
for root posts,True
or others for comments.Actual Behavior
steem.utils.is_comment()
returnsFalse
if the post is a comment but the permlink doesn't start with "re-". As a result, theBlog().take()
results may be lacking comments or list comments as root posts.Steps to reproduce
Reply to a post with a custom permlink that doesn't start with "re-".
Example:
steem.utils.is_comment
is used insteem.blog.take()
and therefore possibly returns wrong results forBlog(comments_only=True)
andBlog(comments_only=False)
:The second result in this example is actually a comment.
Stack Trace
none.
Possible fixes:
This would also avoid the inconsistency of returning
False
for root posts but the parent author as string for comments.Alternatively: remove
steem.utils.is_comment()
and usesteem.post.is_comment()
instead?Posted on Utopian.io - Rewarding Open Source Contributors