Opened 3 weeks ago
Closed 2 weeks ago
#37210 closed Bug (fixed)
Failed deletes in cached_db session backend should log, just like failed writes
| Reported by: | Jacob Walls | Owned by: | Vismay |
|---|---|---|---|
| Component: | contrib.sessions | Version: | 5.1 |
| Severity: | Normal | Keywords: | not-security |
| Cc: | Claude Paroz | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
The Security Team closed a report about the cached_db session backend, but in so doing, we noticed that we recently documented logging any such exceptions for failed writes.
We should handle failed deletes as well, see #34806, which only touched save(), not delete(). (Starting off as "bug" since the docs imply no save-versus-delete distinction, to my ear.)
Thanks LocalHost for the informative report.
Change History (8)
comment:1 by , 3 weeks ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 3 weeks ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:3 by , 3 weeks ago
| Has patch: | set |
|---|
Opened PR: https://github.com/django/django/pull/21606
I reproduced the cache delete failure locally and added sync/async regression tests. The PR makes cached_db delete failures non-fatal and logs them consistently with save failures.
comment:4 by , 3 weeks ago
Just a heads-up:
While logging failed writes in the cache_db session backend is certainly necessary, I believe it would also be appropriate to log the model.DoesNotExist exception in django.contrib.sessions.backends.db—the backend from which cache_db inherits.
That's currently being skipped. It might be out of scope for this ticket.
def delete(self, session_key=None): if session_key is None: if self.session_key is None: return session_key = self.session_key try: self.model.objects.get(session_key=session_key).delete() except self.model.DoesNotExist: pass # <-- silently ignored
comment:5 by , 3 weeks ago
Thanks! I'd lean to keeping this ticket scoped to the cache-delete logging, mirroring what #34806 did for save(). The DoesNotExist handling in the db backend looks intentional to me — deleting a session that's already gone is a normal no-op rather than an error worth logging — so I'd leave it as-is here. Happy to open a separate ticket if a maintainer feels it's worth logging.
comment:6 by , 2 weeks ago
| Patch needs improvement: | set |
|---|
comment:7 by , 2 weeks ago
| Patch needs improvement: | unset |
|---|---|
| Triage Stage: | Accepted → Ready for checkin |
Thanks!