[Django] #33338: Formalize @never_cache setting of Expires header

20 views
Skip to first unread message

Django

unread,
Dec 2, 2021, 2:45:20 PM12/2/21
to django-...@googlegroups.com
#33338: Formalize @never_cache setting of Expires header
-----------------------------------------------+------------------------
Reporter: Andy Chosak | Owner: nobody
Type: Uncategorized | Status: new
Component: Core (Cache system) | Version: 3.2
Severity: Normal | Keywords: cache
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------------+------------------------
The
[https://docs.djangoproject.com/en/dev/topics/http/decorators/#django.views.decorators.cache.never_cache
documentation] for the `@never_cache` decorator says that it sets the
Cache-Control header but neglects to mention that
[https://github.com/django/django/blob/97e9a84d2746f76a635455c13bd512ea408755ac/django/utils/cache.py#L272-L277
it also sets] Expires to the current time (if not already set).

Looking at
[https://github.com/django/django/blame/97e9a84d2746f76a635455c13bd512ea408755ac/django/utils/cache.py#L276
the git blame], the use of Expires for `@never_cache` seems to predate the
more modern Cache-Control. Is Expires still needed/desired as part of
`@never_cache`?

It also feels a little bit unexpected that if `@never_cache` is going to
set Expires as part of its behavior that it would leave alone a pre-
existing Expires header that was set to some far future value.

It would be good to add tests for this behavior to
[https://github.com/django/django/blob/8806e8809e023017e6958b9fa0bbd960938e0a91/tests/decorators/tests.py#L496
the existing tests], both that Expires gets set if not already set and
that, if already set, it doesn't get modified, if that is the desired
behavior.

--
Ticket URL: <https://code.djangoproject.com/ticket/33338>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 3, 2021, 12:58:28 AM12/3/21
to django-...@googlegroups.com
#33338: Formalize @never_cache setting of Expires header
--------------------------------------+------------------------------------

Reporter: Andy Chosak | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Core (Cache system) | Version: 3.2
Severity: Normal | Resolution:
Keywords: cache | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* type: Uncategorized => Cleanup/optimization
* easy: 0 => 1
* stage: Unreviewed => Accepted


Comment:

Agreed, we should clarify that the `Expires` header is added if it isn't
already set in `add_never_cache_headers()` and `@never_cache` docs (see
related `patch_response_headers()`
[https://docs.djangoproject.com/en/stable/ref/utils/#django.utils.cache.patch_response_headerst
docs]). Extra tests are also welcome (as always).

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

Django

unread,
Dec 3, 2021, 12:59:58 AM12/3/21
to django-...@googlegroups.com
#33338: Document that @never_cache and add_never_cache_headers() set the Expires
header.
--------------------------------------+------------------------------------

Reporter: Andy Chosak | Owner: nobody
Type: Cleanup/optimization | Status: new

Component: Core (Cache system) | Version: 3.2
Severity: Normal | Resolution:
Keywords: cache | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/33338#comment:2>

Django

unread,
Dec 8, 2021, 9:38:36 AM12/8/21
to django-...@googlegroups.com
#33338: Document that @never_cache and add_never_cache_headers() set the Expires
header.
-------------------------------------+-------------------------------------
Reporter: Andy Chosak | Owner: Marcelo
Type: | Galigniana
Cleanup/optimization | Status: assigned

Component: Core (Cache system) | Version: 3.2
Severity: Normal | Resolution:
Keywords: cache | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Marcelo Galigniana):

* owner: nobody => Marcelo Galigniana
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/33338#comment:3>

Django

unread,
Dec 8, 2021, 10:25:18 PM12/8/21
to django-...@googlegroups.com
#33338: Document that @never_cache and add_never_cache_headers() set the Expires
header.
-------------------------------------+-------------------------------------
Reporter: Andy Chosak | Owner: Marcelo
Type: | Galigniana
Cleanup/optimization | Status: assigned
Component: Core (Cache system) | Version: 3.2
Severity: Normal | Resolution:
Keywords: cache | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Marcelo Galigniana):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/15167 PR]

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

Django

unread,
Dec 10, 2021, 1:58:19 AM12/10/21
to django-...@googlegroups.com
#33338: Document that @never_cache and add_never_cache_headers() set the Expires
header.
-------------------------------------+-------------------------------------
Reporter: Andy Chosak | Owner: Marcelo
Type: | Galigniana
Cleanup/optimization | Status: assigned
Component: Core (Cache system) | Version: 3.2
Severity: Normal | Resolution:
Keywords: cache | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1


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

Django

unread,
Dec 10, 2021, 6:34:20 AM12/10/21
to django-...@googlegroups.com
#33338: Document that @never_cache and add_never_cache_headers() set the Expires
header.
-------------------------------------+-------------------------------------
Reporter: Andy Chosak | Owner: Marcelo
Type: | Galigniana
Cleanup/optimization | Status: assigned
Component: Core (Cache system) | Version: 3.2
Severity: Normal | Resolution:
Keywords: cache | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Marcelo Galigniana):

[https://github.com/django/django/pull/15176 NEW PR against 'main']

--
Ticket URL: <https://code.djangoproject.com/ticket/33338#comment:6>

Django

unread,
Dec 13, 2021, 3:20:25 AM12/13/21
to django-...@googlegroups.com
#33338: Document that @never_cache and add_never_cache_headers() set the Expires
header.
-------------------------------------+-------------------------------------
Reporter: Andy Chosak | Owner: Marcelo
Type: | Galigniana
Cleanup/optimization | Status: assigned
Component: Core (Cache system) | Version: 3.2
Severity: Normal | Resolution:
Keywords: cache | 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 Mariusz Felisiak):

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


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

Django

unread,
Dec 13, 2021, 12:38:37 PM12/13/21
to django-...@googlegroups.com
#33338: Document that @never_cache and add_never_cache_headers() set the Expires
header.
-------------------------------------+-------------------------------------
Reporter: Andy Chosak | Owner: Marcelo
Type: | Galigniana
Cleanup/optimization | Status: assigned
Component: Core (Cache system) | Version: 3.2
Severity: Normal | Resolution:
Keywords: cache | 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 Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"e61abab6e0d57c333289790496f358bb8ee4c565" e61abab]:
{{{
#!CommitTicketReference repository=""
revision="e61abab6e0d57c333289790496f358bb8ee4c565"
Refs #33338 -- Added never_cache() tests for Expires header.
}}}

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

Django

unread,
Dec 13, 2021, 12:38:38 PM12/13/21
to django-...@googlegroups.com
#33338: Document that @never_cache and add_never_cache_headers() set the Expires
header.
-------------------------------------+-------------------------------------
Reporter: Andy Chosak | Owner: Marcelo
Type: | Galigniana
Cleanup/optimization | Status: closed

Component: Core (Cache system) | Version: 3.2
Severity: Normal | Resolution: fixed

Keywords: cache | 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 Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"669dcefc04837c35fc2ec5ce906d84397005965d" 669dcefc]:
{{{
#!CommitTicketReference repository=""
revision="669dcefc04837c35fc2ec5ce906d84397005965d"
Fixed #33338 -- Doc'd that never_cache() decorator set Expires header.
}}}

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

Django

unread,
Dec 13, 2021, 12:39:15 PM12/13/21
to django-...@googlegroups.com
#33338: Document that @never_cache and add_never_cache_headers() set the Expires
header.
-------------------------------------+-------------------------------------
Reporter: Andy Chosak | Owner: Marcelo
Type: | Galigniana
Cleanup/optimization | Status: closed
Component: Core (Cache system) | Version: 3.2
Severity: Normal | Resolution: fixed
Keywords: cache | 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 Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"cc5bbd447bec57165d5bdf062128fdee0df81ee4" cc5bbd44]:
{{{
#!CommitTicketReference repository=""
revision="cc5bbd447bec57165d5bdf062128fdee0df81ee4"
[4.0.x] Fixed #33338 -- Doc'd that never_cache() decorator set Expires
header.

Backport of 669dcefc04837c35fc2ec5ce906d84397005965d from main
}}}

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

Reply all
Reply to author
Forward
0 new messages