Opened 87 minutes ago

Last modified 84 minutes ago

#36898 new Uncategorized

Document `Session.is_empty`

Reported by: Jake Howard Owned by:
Component: contrib.sessions Version: 4.2
Severity: Normal Keywords:
Cc: jaffar Khan Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

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).

Change History (1)

comment:1 by jaffar Khan, 84 minutes ago

Cc: jaffar Khan added
Note: See TracTickets for help on using tickets.
Back to Top