Skip to content

Error fetching comment by ID #336

Open

Description

@uukelele
Traceback (most recent call last):
  File "main.py", line 160, in replyComment
    comment_obj = user.comment_by_id(commentID)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/pi/.local/lib/python3.11/site-packages/scratchattach/site/user.py", line 730, in comment_by_id
    results = list(filter(lambda x : str(x.id) == str(comment_id), page_content))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not iterable

When I'm replying using the ID of a root-level comment it works fine, but as soon as I attempt to reply using the ID of a reply this error is thrown.

I can't even try replying to the comment with its parent, as I can't even get the comment_obj.

Here's more of my code:

def replyComment(comment, user, commentID):
        user = session.connect_user(user)
        comment_obj = user.comment_by_id(commentID)
        comment_obj.reply(comment)
        return "Comment replied to successfully!"

Activity

  1. faretek1 commented on Jan 26, 2025

    @faretek1
    Collaborator

    I have recently also had problems with the comment system, and found some quirks/scratchattach didn't work for me.
    Perhaps there was an update to the API (possibly at the time when using commentee-id to get username by id was removed) which caused the scratchattach library to go out of date in this respect. It might be something to be investigated

  2. abhiramtx commented on Jan 28, 2025

    @abhiramtx
    Contributor

    Hello! Only replies to top-level comments are shown on the Scratch website. Replies to replies are actually replies to the corresponding top-level comment in the API and aren't different in any way. Thus, you will have to use the parent id of the original comment when trying to reply. The correct syntax to reply to a comment is: user.reply_comment("comment content", parent_id="parent_id", commentee_id=""). Use the commentee_id to notify a user / ping a user about the message (put their user_id) (that is also how replies are handled in the API).

  3. uukelele commented on Jan 28, 2025

    @uukelele
    ContributorAuthor

    Hello! Only replies to top-level comments are shown on the Scratch website. Replies to replies are actually replies to the corresponding top-level comment in the API and aren't different in any way. Thus, you will have to use the parent id of the original comment when trying to reply. The correct syntax to reply to a comment is: user.reply_comment("comment content", parent_id="parent_id", commentee_id=""). Use the commentee_id to notify a user / ping a user about the message (put their user_id) (that is also how replies are handled in the API).

    What you're saying I should do is use the comment ID to get a comment object, then use the parent comment method of that comment to find the parent comment, and finally reply to the parent comment.

    However, I can't even get the comment object from the comment ID.

  4. TheCommCraft commented on Jan 28, 2025

    @TheCommCraft
    Collaborator
  5. uukelele commented on Jan 28, 2025

    @uukelele
    ContributorAuthor

    Interesting. Sometimes, when viewing the comments page, recent comments don't show. Perhaps something needs to be added in this function to handle empty comment pages.

  6. faretek1 commented on Jan 24, 2026

    @faretek1
    Collaborator

    the get_comment_by_id function is kind of flawed because of the dynamic nature of comment pages. On e.g. griffpatch's profile, you can miss comments because so many comments are made per second that the push older comments further and further into the high page indexes. In theory, so many comments could be made/second that every time you increment the page # and view the next set of comments, you could be viewing the same comments again.

    This is why I did not finish #554

  7. uukelele commented on Jan 24, 2026

    @uukelele
    ContributorAuthor

    I think the problem is that when you post a comment on a page and reload it, it has a seemingly random chance to just not show up. This usually only happens for extremely recent comments.

    My best guess would be that scratch is using a load balancer and multiple servers, and when one server receives the message it can update the database + its cache, but other servers will maybe have an outdated cache. But then it's very specific and I might be wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions