scratchattach icon indicating copy to clipboard operation
scratchattach copied to clipboard

[Bug]: client.get_requester() doesn't always work

Open redspacecat opened this issue 5 months ago • 11 comments

scratchattach version

2.1.13

What happened?

Sometimes when calling client.get_requester() it returns None.

It seems that this is because in load_log_data of CloudActivity the matching list doesn't find any matches because the timestamp doesn't account for the time it takes to fetch the cloud logs.

Your code.

@client.request
def example():
    return client.get_requester()

Traceback

none

redspacecat avatar Aug 14 '25 18:08 redspacecat

have you actually experienced this?

TheCommCraft avatar Aug 14 '25 22:08 TheCommCraft

have you actually experienced this?

Yes, I have been experiencing this. I had to edit the scratchattach package code to make a workaround so I can use scratchattach.

redspacecat avatar Aug 14 '25 23:08 redspacecat

could you give your source code

TheCommCraft avatar Aug 15 '25 15:08 TheCommCraft

My code is just the example code with a different function name. Here's an example from my code:

@client.request
def ping():
    print("Ping request from", client.get_requester())
    return "pong"

If you want all of my code:

Code
import scratchattach as sa
import warnings

warnings.filterwarnings('ignore', category=sa.LoginDataWarning)
session = sa.login_by_id([REDACTED])
conn = session.connect_cloud([REDACTED])
client = conn.requests()

@client.request
def ping():
    print("Ping request from", client.get_requester())
    return "pong"

@client.request
def save_level(id, level_data):
    user = client.get_requester()
    if not user:
        return "500"
    print(user, "is saving the level with id", id)
	return level_data
	

@client.event
def on_ready():
    print("Request handler is running")

client.start()

redspacecat avatar Aug 15 '25 17:08 redspacecat

And you have tried this in isolation? It would be good to have more context as this doesn't happen normally. I personally have a server where this hasn't ever happened to my knowledge.

TheCommCraft avatar Aug 15 '25 19:08 TheCommCraft

Your code raises a SyntaxError. Your problem might be caused because of the server you are using, have you tried this on your own PC?

TheCommCraft avatar Aug 15 '25 20:08 TheCommCraft

Your code raises a SyntaxError. Your problem might be caused because of the server you are using, have you tried this on your own PC?

It raises a SyntaxError because I redacted my session id and project. I've been running it on my computer the whole time.

redspacecat avatar Aug 15 '25 20:08 redspacecat

And you have tried this in isolation? It would be good to have more context as this doesn't happen normally. I personally have a server where this hasn't ever happened to my knowledge.

It seems to come and go. Sometimes it works, sometimes it doesn't.

redspacecat avatar Aug 15 '25 20:08 redspacecat

I'm going to test a bit more and see if I can make it more reproducible.

redspacecat avatar Aug 15 '25 20:08 redspacecat

This happens quite a bit with my project where it will return the default balance to the user as it thinks the username is "none" this has been present since 1.4.7 or before as it is in the first 25 users saved in my project.

wvzack avatar Aug 29 '25 03:08 wvzack

It may be possible to create a drop-in replacement for client.get_requester if we can add an option to pass in an optional keyword-only argument called event which could contain data like the timestamp, the set value, etc

faretek1 avatar Sep 29 '25 23:09 faretek1