Persistant connections doesn't work properly after migrating to Django 4.2

Hi,
after migrating from django 3.2 to 4.2 I’ve noticed persistant connections doesn’t work the same for the new version.
I’m using CONN_MAX_AGE=20 setting

For Django 3.2 I can see that oracle doesn’t create new sessions in v$session table on each request.
But in Django 4.2 there is new session created for each request even though we haven’t changed anything in the database connections.

STACK:

  • python 3.9.16
  • django 4.2.5
  • oracle 19.16.0

Any ideas how to recreate the old behaviour on the new version of Django?

Hi,

I don’t know what the issue would be but… If you’re confident that nothing changed in your code, there are ways to check & isolate changes in Django that may have caused it:

Did you happen to upgrade release at-a-time ie 3.2 → 4.0 → 4.1 → 4.2 … and if so … do you know which step the issue started happening?

If you jumped straight to 4.2 then setting up a separate local dev environment and checking which release caused it may be the go. If you feel like a challenge perhaps you could also bisect to the exact commit in Django.

Django 4.1 introduced the default-off setting CONN_HEALTH_CHECKS, which enables an extra per-check request for persistent connections. I think this would be the biggest change to database connection logic between the two versions. It could be that the commit that added this feature changed something (perhaps Oracle-only) in a way that others haven’t yet found.

Maybe try reverting that commit in your own fork (or comment out calls to close_if_health_check_failed). Or try enabling CONN_HEALTH_CHECKS to see if that changes anything.

1 Like