[Django] #36003: Add `connection_closed` or `pre_connection_closed` and `post_connection_closed` signals

7 views
Skip to first unread message

Django

unread,
Dec 12, 2024, 3:14:04 AM12/12/24
to django-...@googlegroups.com
#36003: Add `connection_closed` or `pre_connection_closed` and
`post_connection_closed` signals
-------------------------------------+-------------------------------------
Reporter: Tomasz | Owner: Tomasz Wójcik
Wójcik |
Type: New | Status: assigned
feature |
Component: Database | Version: dev
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
Currently I'm facing an issue with stale DB connections. It's probably
related to my setup. Having `connection_closed` signal would simplify my
debugging process.

Since 2009, there's `connection_created` signal.

https://github.com/django/django/blame/6f38697f90a14f1450a71c1e40aea0f5df7dca86/django/db/backends/signals.py

I'd like to create a `connection_closed` signal and connect it here

https://github.com/django/django/blob/6f38697f90a14f1450a71c1e40aea0f5df7dca86/django/db/backends/base/base.py#L314

This way the connection can be accessed right before closing it.

I'd be happy to implement it. Let me know what you think.

I'm also open to `pre_connection_closed` and `post_connection_closed`.
Even though not many people will ever use it, I can imagine wanting both
in different cases.
--
Ticket URL: <https://code.djangoproject.com/ticket/36003>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 12, 2024, 4:23:58 AM12/12/24
to django-...@googlegroups.com
#36003: Add `connection_closed` or `pre_connection_closed` and
`post_connection_closed` signals
-------------------------------------+-------------------------------------
Reporter: Tomasz Wójcik | Owner: Tomasz
| Wójcik
Type: New feature | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* resolution: => wontfix
* status: assigned => closed

Comment:

Can you propose and discuss the idea with the community on the
[https://forum.djangoproject.com/c/internals/5 Django Forum]? There you'll
reach a broader audience and receive additional feedback.

If the community agrees with the proposal, please return to this ticket
and reference the forum discussion so we can re-open it. For more
information, please refer to
[https://docs.djangoproject.com/en/stable/internals/contributing/bugs-and-
features/#requesting-features the documented guidelines for requesting
features].
--
Ticket URL: <https://code.djangoproject.com/ticket/36003#comment:1>

Django

unread,
Jan 9, 2025, 5:11:19 AM1/9/25
to django-...@googlegroups.com
#36003: Add `connection_closed` or `pre_connection_closed` and
`post_connection_closed` signals
-------------------------------------+-------------------------------------
Reporter: Tomasz Wójcik | Owner: Tomasz
| Wójcik
Type: New feature | Status: closed
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Tomasz Wójcik:

Old description:

> Currently I'm facing an issue with stale DB connections. It's probably
> related to my setup. Having `connection_closed` signal would simplify my
> debugging process.
>
> Since 2009, there's `connection_created` signal.
>
> https://github.com/django/django/blame/6f38697f90a14f1450a71c1e40aea0f5df7dca86/django/db/backends/signals.py
>
> I'd like to create a `connection_closed` signal and connect it here
>
> https://github.com/django/django/blob/6f38697f90a14f1450a71c1e40aea0f5df7dca86/django/db/backends/base/base.py#L314
>
> This way the connection can be accessed right before closing it.
>
> I'd be happy to implement it. Let me know what you think.
>
> I'm also open to `pre_connection_closed` and `post_connection_closed`.
> Even though not many people will ever use it, I can imagine wanting both
> in different cases.

New description:

Currently I'm facing an issue with stale DB connections. It's probably
related to my setup. Having `connection_closed` signal would simplify my
debugging process.

Since 2009, there's `connection_created` signal.

https://github.com/django/django/blame/6f38697f90a14f1450a71c1e40aea0f5df7dca86/django/db/backends/signals.py

I'd like to create a `connection_closed` signal and connect it here

https://github.com/django/django/blob/6f38697f90a14f1450a71c1e40aea0f5df7dca86/django/db/backends/base/base.py#L314

This way the connection can be accessed right before closing it.

I'd be happy to implement it. Let me know what you think.

I'm also open to `pre_connection_closed` and `post_connection_closed`.
Even though not many people will ever use it, I can imagine wanting both
in different cases.


EDIT: Posted on Django forum https://forum.djangoproject.com/t/add-
connection-closed-or-pre-connection-closed-and-post-connection-closed-
signals/37819

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36003#comment:2>
Reply all
Reply to author
Forward
0 new messages