Opened 7 years ago

Closed 7 years ago

#29073 closed Bug (invalid)

CONN_MAX_AGE and others not being picked up from settings file

Reported by: Karl Kuehn Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In trying to solve some performance issues I am observing (probably our code) I tried to use the CONN_MAX_AGE setting documented here:
https://docs.djangoproject.com/en/2.0/ref/settings/#conn-max-age

I have a pgbouncer instance setup, so it was easy to observe connections going to the database, and I found that regardless of that setting the connections were being dropped at the end of every request, regardless of what value I set (even invalid ones have no effect).

Using git grep CONN_MAX_AGE | grep '\.py:' I found that this value is never being read from the settings file, and only defaulted in django/db/utils.py:ConnectionHandler.ensure_defaults(). This is true both on current (as of this writing) master and version 1.11.1 (what we are currently using). It may well go farther back than that, but I have not checked.

I also checked ATOMIC_REQUESTS, and AUTOCOMMIT and they show the same pattern. Other values there are more complicated, and I did not check.

Change History (2)

comment:1 by Karl Kuehn, 7 years ago

I have created a pull request with one way of fixing this: https://github.com/django/django/pull/9625

comment:2 by Tim Graham, 7 years ago

Resolution: invalid
Status: newclosed

As Simon said on the pull request, "These settings should be defined per-DATABASES entry and not as top level settings."

Note: See TracTickets for help on using tickets.
Back to Top