#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 <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/0107019c1f19e20b-835578be-1998-465d-94e9-0695512a7382-000000%40eu-central-1.amazonses.com.

Reply via email to