[Django] #36898: Document `Session.is_empty`

0 views
Skip to first unread message

Django

unread,
Feb 2, 2026, 5:44:18 AM (3 days ago) Feb 2
to django-...@googlegroups.com
#36898: Document `Session.is_empty`
-----------------------------+--------------------------------------------
Reporter: Jake Howard | Type: Uncategorized
Status: new | Component: contrib.sessions
Version: 4.2 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+--------------------------------------------
It's often useful to check whether the user has a session, for example to
avoid creating one unnecessarily. Since `request.session` is always
populated when `SessionMiddleware` is used, it's better to check whether
the session is empty. `BaseSession` has a `is_empty` method, but it's
undocumented.

It should be documented.

Additionally, perhaps `BaseSession.__bool__` should exist, so `if
request.session` works as expected? The downside being `if
getattr(request, "session", None)` would be `False` when sessions are
being used, but the session is empty (arguably `hasattr` would be better
there anyway).
--
Ticket URL: <https://code.djangoproject.com/ticket/36898>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 2, 2026, 5:47:19 AM (3 days ago) Feb 2
to django-...@googlegroups.com
#36898: Document `Session.is_empty`
----------------------------------+--------------------------------------
Reporter: Jake Howard | Owner: (none)
Type: Uncategorized | Status: new
Component: contrib.sessions | Version: 4.2
Severity: Normal | Resolution:
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 jaffar Khan):

* cc: jaffar Khan (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/36898#comment:1>

Django

unread,
Feb 2, 2026, 10:33:45 AM (2 days ago) Feb 2
to django-...@googlegroups.com
#36898: Document `Session.is_empty`
--------------------------------------+------------------------------------
Reporter: Jake Howard | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Jacob Walls):

* component: contrib.sessions => Documentation
* stage: Unreviewed => Accepted
* type: Uncategorized => Cleanup/optimization

Comment:

Thanks. Let's break out the `__bool__` discussion somewhere else so that
we can keep the doc fix on the fast-track.
--
Ticket URL: <https://code.djangoproject.com/ticket/36898#comment:2>

Django

unread,
Feb 2, 2026, 10:41:27 AM (2 days ago) Feb 2
to django-...@googlegroups.com
#36898: Document `Session.is_empty`
-------------------------------------+-------------------------------------
Reporter: Jake Howard | Owner: jaffar
Type: | Khan
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jaffar Khan):

* owner: (none) => jaffar Khan
* status: new => assigned

Comment:

Want to work on this ticket
--
Ticket URL: <https://code.djangoproject.com/ticket/36898#comment:3>

Django

unread,
Feb 2, 2026, 11:05:23 AM (2 days ago) Feb 2
to django-...@googlegroups.com
#36898: Document `Session.is_empty`
-------------------------------------+-------------------------------------
Reporter: Jake Howard | Owner: jaffar
Type: | Khan
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Jake Howard:

Old description:

> It's often useful to check whether the user has a session, for example to
> avoid creating one unnecessarily. Since `request.session` is always
> populated when `SessionMiddleware` is used, it's better to check whether
> the session is empty. `BaseSession` has a `is_empty` method, but it's
> undocumented.
>
> It should be documented.
>
> Additionally, perhaps `BaseSession.__bool__` should exist, so `if
> request.session` works as expected? The downside being `if
> getattr(request, "session", None)` would be `False` when sessions are
> being used, but the session is empty (arguably `hasattr` would be better
> there anyway).

New description:

It's often useful to check whether the user has a session, for example to
avoid creating one unnecessarily. Since `request.session` is always
populated when `SessionMiddleware` is used, it's better to check whether
the session is empty. `BaseSession` has a `is_empty` method, but it's
undocumented.

It should be documented.

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36898#comment:4>

Django

unread,
Feb 2, 2026, 1:00:59 PM (2 days ago) Feb 2
to django-...@googlegroups.com
#36898: Document `Session.is_empty`
-------------------------------------+-------------------------------------
Reporter: Jake Howard | Owner: jaffar
Type: | Khan
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jaffar Khan):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36898#comment:5>

Django

unread,
Feb 2, 2026, 1:07:33 PM (2 days ago) Feb 2
to django-...@googlegroups.com
#36898: Document `Session.is_empty`
-------------------------------------+-------------------------------------
Reporter: Jake Howard | Owner: jaffar
Type: | Khan
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by jaffar Khan):

PR https://github.com/django/django/pull/20630
--
Ticket URL: <https://code.djangoproject.com/ticket/36898#comment:6>

Django

unread,
Feb 2, 2026, 2:03:18 PM (2 days ago) Feb 2
to django-...@googlegroups.com
#36898: Document `Session.is_empty`
-------------------------------------+-------------------------------------
Reporter: Jake Howard | Owner: jaffar
Type: | Khan
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36898#comment:7>

Django

unread,
Feb 2, 2026, 8:35:33 PM (2 days ago) Feb 2
to django-...@googlegroups.com
#36898: Document `Session.is_empty`
-------------------------------------+-------------------------------------
Reporter: Jake Howard | Owner: jaffar
Type: | Khan
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/36898#comment:8>

Django

unread,
Feb 2, 2026, 9:04:25 PM (2 days ago) Feb 2
to django-...@googlegroups.com
#36898: Document `Session.is_empty`
-------------------------------------+-------------------------------------
Reporter: Jake Howard | Owner: jaffar
Type: | Khan
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 0 => 1
* stage: Ready for checkin => Accepted

--
Ticket URL: <https://code.djangoproject.com/ticket/36898#comment:9>

Django

unread,
Feb 3, 2026, 11:01:29 AM (yesterday) Feb 3
to django-...@googlegroups.com
#36898: Document `Session.is_empty`
-------------------------------------+-------------------------------------
Reporter: Jake Howard | Owner: jaffar
Type: | Khan
Cleanup/optimization | Status: assigned
Component: Documentation | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/36898#comment:10>

Django

unread,
Feb 3, 2026, 11:08:55 AM (yesterday) Feb 3
to django-...@googlegroups.com
#36898: Document `Session.is_empty`
-------------------------------------+-------------------------------------
Reporter: Jake Howard | Owner: jaffar
Type: | Khan
Cleanup/optimization | Status: closed
Component: Documentation | Version: 4.2
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls <jacobtylerwalls@…>):

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

Comment:

In [changeset:"13299a6203f4bc3e5b2552c96a51ff2b15da3c43" 13299a6]:
{{{#!CommitTicketReference repository=""
revision="13299a6203f4bc3e5b2552c96a51ff2b15da3c43"
Fixed #36898 -- Documented SessionBase.is_empty().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36898#comment:11>

Django

unread,
Feb 3, 2026, 11:09:14 AM (yesterday) Feb 3
to django-...@googlegroups.com
#36898: Document `Session.is_empty`
-------------------------------------+-------------------------------------
Reporter: Jake Howard | Owner: jaffar
Type: | Khan
Cleanup/optimization | Status: closed
Component: Documentation | Version: 4.2
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls <jacobtylerwalls@…>):

In [changeset:"03a15d1063f53059ee934f487503ade2fbc1e39d" 03a15d1]:
{{{#!CommitTicketReference repository=""
revision="03a15d1063f53059ee934f487503ade2fbc1e39d"
[6.0.x] Fixed #36898 -- Documented SessionBase.is_empty().

Backport of 13299a6203f4bc3e5b2552c96a51ff2b15da3c43 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36898#comment:12>
Reply all
Reply to author
Forward
0 new messages