#37252 new Bug

If-Unmodified-Since yields 412 when the resource has no modification date, instead of being ignored (RFC 9110 13.1.4)

Reported by: Eugene Lazutkin Owned by:
Component: HTTP handling Version: dev
Severity: Normal Keywords:
Cc: Eugene Lazutkin Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

RFC 9110 ยง13.1.4: "A recipient MUST ignore the If-Unmodified-Since header field if the resource does not have a modification date available."

_if_unmodified_since_passes in django/utils/cache.py fails when last_modified is not available:

def _if_unmodified_since_passes(last_modified, if_unmodified_since):
    return last_modified and last_modified <= if_unmodified_since

so get_conditional_response answers 412 (Precondition Failed) where the RFC says the header must be ignored. Reproducible on any path with no Last-Modified available โ€” e.g. @condition with only an etag_func, or ConditionalGetMiddleware on a response without the header โ€” when the request carries If-Unmodified-Since.

The _if_modified_since_passes twin is already ignore-shaped (not last_modified or ...), so the fix is one line mirroring it: return not last_modified or last_modified <= if_unmodified_since.

Would you accept a PR (patch + tests) for this?

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top