Trying to use Replit Database in a deployment but getting 'NoneType' object does not support item assignment Are these available for use in deployments? It works fine when just running the Replit.
Sure, thanks. I think the db object from from replit import db isn’t getting instantiated? I’m not sure why this would work when running from console but not when running in a deployment, though.
2023-07-18 13:33:02 - 'NoneType' object does not support item assignment
Traceback (most recent call last):
File "/home/runner/3b32ffbd-dee3-4af0-9ba9-b3c2fb857b1f/venv/lib/python3.10/site-packages/chainlit/utils.py", line 36, in wrapper
return await user_function(**params_values)
File "/home/runner/3b32ffbd-dee3-4af0-9ba9-b3c2fb857b1f/main.py", line 127, in process_response
db[timestamp] = res
TypeError: 'NoneType' object does not support item assignment
Welcome to Ask! Looking at your Replit profile, you appear to have no Repls. I assume this is a private Repl. Could you either make it public (preferred) or provide a code snippet?
How to use ReplDB (just in case this solves your problem)
from replit import db
db["my_db"] = {}
db["my_db"].update({"name":"bob"})
# You can just keep making db's and
# adding to them
# IIRC it supports lists too
Deployments do not have persistent filesystems so anything written to the deployment while it’s running will go away if it is re-run (if it can be written to it at all). However, my understanding is that ReplDB is meant to mitigate this issue, so that you can save data to a database instead of your filesystem. So this may be a bug. Still your code would be helpful.
I’m troubleshooting & will share my findings, but my working hypothesis is that db is None when I import it in the deployment environment only for some reason.
will show db is None in your Deployment logs, but when running the Replit via Run, will show the db info 2023-07-18 23:28:40 - db is <Database(db_url='https://kv.replit.com/v0/...