Inércia Sensorial

02 de January de 2021

Django PostgreSQL used session on Github Actions test error

Filed under: Python — Tags: , , , — inerte @ 16:26

If you’re using the PostgreSQL service on Github Actions as a backend database for your Django tests, you might encounter the following error on any particular test:

django.db.utils.OperationalError: database "test_name" is being accessed by other users
DETAIL:  There is 1 other session using the database.

And the following at the end of your test run:

RuntimeError: generator didn't stop after throw()

The problem is that Django reuses the database connection, and while locally my tests were passing, on Github Actions even though the all tests were passing, somehow a connection to the database created by the tests was still open, and I was getting the error above.

The solution is simple, set CONN_MAX_AGE to 0 (or conn_max_age if you use dj_database_url) on your DATABASES settings when running on Github Actions.

Powered by WordPress