AttributeError: 'Response' object has no attribute 'status_code'
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- prometheus, python
- Domain
- backend, observability
Research direction
Start in common/gunicorn/logging.py at PrometheusGunicornLogger.access(), then compare the error path in gunicorn/workers/base.py with normal response handling. Reproduce or inspect the malformed-header path from the traceback and verify that logging it no longer raises AttributeError while retaining the available response status.
Written by the indexing model from the issue text.
Description
Sentry Issue: FLAGSMITH-API-69B
InvalidHeader: Invalid HTTP Header: 'TRANSFER-ENCODING'
(1 additional frame(s) were not displayed)
...
File "gunicorn/http/parser.py", line 41, in __next__
self.mesg = self.mesg_class(self.cfg, self.unreader, self.source_addr, self.req_count)
File "gunicorn/http/message.py", line 259, in __init__
super().__init__(cfg, unreader, peer_addr)
File "gunicorn/http/message.py", line 62, in __init__
self.set_body_reader()
File "gunicorn/http/message.py", line 461, in set_body_reader
super().set_body_reader()
File "gunicorn/http/message.py", line 186, in set_body_reader
raise InvalidHeader("TRANSFER-ENCODING", req=self)
AttributeError: 'Response' object has no attribute 'status_code'
(3 additional frame(s) were not displayed)
...
File "gunicorn/workers/sync.py", line 69, in run_for_one
self.accept(listener)
File "gunicorn/workers/sync.py", line 31, in accept
self.handle(listener, client, addr)
File "gunicorn/workers/sync.py", line 157, in handle
self.handle_error(req, client, addr, e)
File "gunicorn/workers/base.py", line 278, in handle_error
self.log.access(resp, req, environ, request_time)
File "common/gunicorn/logging.py", line 37, in access
"response_status": resp.status_code,
Exception in worker process
Root cause
When gunicorn rejects a request during parsing, handle_error() builds the Response by hand and sets only resp.status. Our PrometheusGunicornLogger.access() reads resp.status_code, which then raises AttributeError.
Suggested fix
Read the status resiliently on the error path rather than assuming status_code exists — e.g. getattr(resp, "status_code", None), or derive it from resp.status (int(resp.status.split()[0]) when resp.status is a string), mirroring how gunicorn's own logger tolerates responses that never went through start_response().
- Dominant language
- Python
- Stars
- 2
- Forks
- 4
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 10
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Flagsmith/flagsmith-common
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Flagsmith/flagsmith-common#198 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
Flagsmith/flagsmith-common#254 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Flagsmith/flagsmith-common#252 ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
Flagsmith/flagsmith-common#245 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
Flagsmith/flagsmith-common#222 · 2 reactions ·
All issues in Flagsmith/flagsmith-common
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100