Replies: 3 comments
-
Do you attach a debugger? I'm not able to reproduce the error. Does it also happen with a minimal app (eg "hello world")? Is it always happening if you have multiple browser tabs open or only sometimes? |
Beta Was this translation helpful? Give feedback.
-
Hi Rodja, thank you for taking a look. Your questions prompted me to take a closer look, and I've narrowed it down to the interface with Tortoise ORM and aiosqlite: both ValueErrors (below and above) originate in aiosqlite.core.py. To reproduce, take the sqlite example in the repo and comment out the generate_schemas in the init (after first creating the db): register_tortoise(
app,
db_url="sqlite://db.sqlite3",
modules={"models": ["models"]}, # tortoise will look for models in this main module
# generate_schemas=True, # in production you should use version control migrations instead
) Open two browser sessions, not sharing cookies (eg, one should be incognito). Then make a trivial edit in main.py, causing a reload. You should see this error:
I have added the generate_schemas call to my own init code and I no longer get the 'Connection closed' error when reloading. So for me, the issue is resolved. It does feel a bit shaky that these errors in underlying coroutines (?) cannot be surfaced properly, but it's totally up to you how deep you want to get into this, of course. Cheers, -Peter |
Beta Was this translation helpful? Give feedback.
-
It would be good to dig deeper and try to find a even more minimal reproduction without NiceGUI to post the issue in the Tortoise repo. Thanks to your analysis I think it is not really something caused by NiceGUI, so I'll close the issue. Thanks! |
Beta Was this translation helpful? Give feedback.
-
This is not really a bug, more of an inconvenience - and primarily caused by starlette/fastapi, I think [EDIT: aiosqlite, in fact]. While debugging I have a number of browser windows open. When I have edited the source and the app automatically reloads, I get a long "flag" of errors that is apparently caused by the server side trying to handle
websocketdatabase connections that have gone stale. See below.When I interrupt the console and manually restart (or if I close all browser windows!), this is clean.
Anyone have a suggestion how to do a "clean" reload, ie get rid of the old state when doing ui.run?
Cheers, -Peter
fastapi==0.97.0
starlette==0.27.0
nicegui==1.3.7
(Btw, it's hard to post a "minimal" app to reproduce this. Not sure what triggers this behavior. Multiple browser sessions is certainly one factor.)
Beta Was this translation helpful? Give feedback.
All reactions