﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
37523	HttpResponse crashes when reason is a lazy string or reason_phrase is a read-only property	Mariano Ignacio Baragiola	Mariano Ignacio Baragiola	"Since 53645750412efa1e9013004040db328bd515e0f1 (#37100, backported to 6.1 as d7b3fed6a1), `HttpResponseBase.__init__()` sets the reason through the `reason_phrase` setter, and the setter runs `_control_chars_re.search(value)`. Two cases that worked in Django 6.0 now fail.

1. A lazy string as `reason` raises `TypeError`:

{{{#!python
from django.http import HttpResponse
from django.utils.translation import gettext_lazy

HttpResponse(status=418, reason=gettext_lazy(""Custom reason""))
}}}

{{{
TypeError: expected string or bytes-like object, got '__proxy__'
}}}

The same happens with `response.reason_phrase = gettext_lazy(""..."")`.

2. A subclass that defines `reason_phrase` as a getter-only property raises `AttributeError` when created:

{{{#!python
from django.http import HttpResponse

class CustomResponse(HttpResponse):
    @property
    def reason_phrase(self):
        return ""Custom reason""

CustomResponse(status=418)
}}}

{{{
AttributeError: property 'reason_phrase' of 'CustomResponse' object has no setter
}}}

Expected: both work as in 6.0, and control characters are still rejected (lazy strings included).

Affected: 6.1.0 to 6.1.3 and main. Regression in 53645750412efa1e9013004040db328bd515e0f1.

Suggested fix: run the control character check on `str(value)` when the value is not `None`, and have `__init__()` run the check and set `_reason_phrase` directly instead of going through the setter.

AI disclosure: I found and reproduced this with Claude Code (Anthropic)."	Bug	assigned	HTTP handling	6.1	Release blocker				Unreviewed	0	0	0	0	0	0
