New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In on_connect hook: RuntimeError: app.storage.user needs a storage_secret passed in ui.run() #2520
Comments
Hi @dr-yd, thanks for reporting this problem! Here is a minimal reproduction: from nicegui import ui, app
@ui.page('/')
def root():
app.on_connect(lambda: print(app.storage.user.get('test')))
ui.run(storage_secret='foobar') But I haven't found the reason why we see this specific error message. The Even though we should fix this misleading RuntimeError, the following code works as expected: from nicegui import Client, app, ui
@ui.page('/')
async def root(client: Client):
await client.connected()
app.storage.user.get('test')
ui.run(storage_secret='foobar') |
Since we'll change how requests are stored in the |
I'm seeing a similar issue. I'm trying to get Oauth2 working (mostly have succeeded) and am now trying to add password authentication. I'm running uvicorn from fastapi and then using:
With breakpoints I traced that storage_secret seems to be getting added (with sessionMiddleware), but later when I try check app.storage.user the key is not there
p.s. I'm also trying to use app.add_middleware(AuthMiddleware) |
In #2662 we noticed another example for the misleading "RuntimeError: app.storage.user needs a storage_secret passed in ui.run()": @ui.page('/')
def page():
ui.label('Hello, world!')
app.on_disconnect(lambda: print(app.storage.user)) |
Hi all, @ui.page("/")
async def main(client: Client):
await client.connected()
async def on_click():
result = await run.io_bound(run_analysis) # Run in async.
ui.button("Run", on_click=lambda: on_click())
def run_analysis():
return app.storage.user["test"]
# Main guard to be used for testing.
if __name__ in {"__main__", "__mp_main__"}:
ui.run(storage_secret="test_secret!") The above results in @ui.page("/")
async def main(client: Client):
await client.connected()
async def on_click():
result = run_analysis() # Not run in async.
ui.button("Run", on_click=lambda: on_click())
def run_analysis():
return app.storage.user["test"]
# Main guard to be used for testing.
if __name__ in {"__main__", "__mp_main__"}:
ui.run(storage_secret="test_secret!") |
Hi - I also have this problem... don't suppose anyone has a workaround? |
okay, this seems to be fixed in the latest version! |
@Dan1001 As far as I can tell, my reproduction from #2520 (comment) still causes the RuntimeError. |
that's funny - I'm now getting it in some circumstances but not others (sorry, I know that's very unhelpful; complex code). I'll try to work out why... |
This happens to me as well, when using run.io_bound. I somehow figured if my function within "io_bound" has an issue (key not found for dict for example), logger.debug is not showing anything but giving this error, along with |
Update (and possibly a workaround) on my code. It seems like a race condition when you try to update app.storage very fast. I have a process checking the status of a REST call every few seconds, and based on the fields of the returned json, I update the status on the persistent storage. In this case, I am using With the following piece of code, if I have this I don't know exactly why it works for the first two consecutive updates, but fails on the third. Hope this helps figuring out best way to handle this type of situation (assuming this is the reason). elif result['status'] == "OK":
app.storage.general["stream_replication"] = "OK"
if result["data"][0].get('replicaState', "") == "REPLICA_STATE_REPLICATING":
app.storage.general["stream_replication"] = "REPLICATING"
if result["data"][0].get("isUptodate", False) == True:
sleep(0.2)
app.storage.general["stream_replication"] = "IN SYNC" |
I'm experiencing the exact same issue and I got to the same conclusion: whenever It happens the same with |
Description
Code example:
Result:
Intent in the actual application is to initialize a session to a remote server if the user has an active OAuth session with that server. And that session would be stored in the user storage. At the very least, the message is misleading, but I'm not sure how to do this properly.
The text was updated successfully, but these errors were encountered: