oTree Forum >

OperationalError: running oTree on Heroku (and Render)

#1 by Afshin

Hi,

We have successfully run 15 sessions of a generalized war of attrition over the past year on Heroku and very recently encountered this error:

OperationalError: (raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely) (sqlite3.OperationalError) database is locked [SQL: UPDATE otree_participant SET _last_request_timestamp=? WHERE otree_participant.id = ?] [parameters: (1731932708, 17)] (Background on this error at: http://sqlalche.me/e/13/e3q8)

I am using oTree 5.10.4 on Python 3.9.0 and deploy the game onto Heroku via GitHub. I don't use Postgres or any other SQL database; instead, we download the data as a .csv file from the Data tab of oTree after the game ends. The last time we managed to run a game with 27 participants was on 30 October 2024. Today we tried the same game (by rolling back to the same version on Heroku)) and it crashed with error messages like the one copied above for several players.

I had tried the same game on Render and the same problems happened there too. My suspicion is that there might be some recent change / update in the oTree side that causes this problem. Below I copy the last traceback prior to the above error message for quick reference:

Traceback

File /app/.heroku/python/lib/python3.11/site-packages/sqlalchemy/engine/default.py, line 609, in do_execute‒

606.         cursor.executemany(statement, parameters)
607.
608.     def do_execute(self, cursor, statement, parameters, context=None):
609.         cursor.execute(statement, parameters)
610.
611.     def do_execute_no_params(self, cursor, statement, context=None):
612.         cursor.execute(statement)

I appreciate any help and guidance to be able to complete our experiments after more than a year.

Thanks,
Afshin

#2 by Afshin

Thanks to the Generative AI, I managed to find a solution! As per the AI Chatbots (Google Gemini and Microsoft Copilot), the error message "OperationalError: database is locked" indicates that the SQLite database used by the oTree project on Heroku is locked and cannot be written to. This can happen for several reasons. The first recommendation was to consider switching to Postgres. 

Subsequently, I added Postgres as an add-on to my oTree application on Heroku that resolved the problem.

Hope these help other oTree users!

Write a reply

Set forum username