How to Solve the Problem of Github Actions Django Test Failing to Destroy PostgreSQL Database?
TL;DR
Description
My Solution
1. I removed the conn_max_age=600 from my dj_database_url.config.
Possible Variations
1. Find your PostgreSQL connection configuration. If there is a configuration similar to the maximum time the system will keep the connection alive, set it to 0 or remove it so that the default 0 will be used. This essentially means it will close the connection once it is done.
The Full Story
Introduction
I have one repository where I am doing my final project for CS50 Web. I changed my project from a task manager to a 90-day notification tracker because it is something that I see myself using. After I've changed the model and committed my code, I started to see the following error in my Github Actions test.
Thinking Process
First thought
My first suspicion is the version of the program so I tried to specify the version of Django and psycopg2. I changed it to an older version to no avail.
Stackoverflow
Most of the posts suggested either we restart the database or revoke some connection rights which doesn't help in this case.
Django Test -- Unable to drop and recreate test database
Postgresql - unable to drop database because of some auto connections to DB
The Breakthrough
The breakthrough came when I read that Django's CONN_MAX_AGE's default value is 0 and it means that the database connection is closed at the end of the request. Upon closer inspection, I found that my dj_database_url's configuration is the same as the sample in its PyPI listing which is dj_database_url.config(conn_max_age=600, ssl_require=True)
The Solution
Removing the conn_max_age=600 from dj_database_url solves the problem because the default value of this is 0 which also means that the database connection is closed at the end of the request.
Comments
Post a Comment