Repository navigation
Conversation
Reviewer's GuideImplementationRename the tuple-unpack discard targets in the content handler patch so they no longer shadow gettext’s
DocumentationRecord the PULP-2717 fix in the changelog.
TestsAdd a functional regression test confirming that a distribution without a configured content source returns 404 with the expected reason.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Patch 0080 used a bare `_` as the throwaway target of three tuple unpacks in Handler._match_and_stream, which made `_` a function-local name and shadowed gettext's `_`. A distribution with no repository, publication, or remote reaches the "Distribution is not pointing to..." branch without executing any of those unpacks, so the gettext call raised UnboundLocalError and the content app returned 500 instead of 404. Same shadowing turned upstream fetch failures into TypeError: 'QuerySet' object is not callable. Rename the discard target to `_lazy_queryset` and add a functional regression test for the empty-distribution path. Refs: GlitchTip PULP-PROD-5J2 (1,433 events since 2026-11-02) Assisted-by: Opencode (DeepSeek-V4.1-Flash-1017)
1d4a92a to
802e476
Compare
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="pulp_service/pulp_service/tests/functional/test_content_handler.py" line_range="48" />
<code_context>
+ response = requests.get(f"{distro.base_url}missing/path", timeout=30)
+
+ assert response.status_code == 404, response.text
+ assert "Distribution is not pointing to" in response.reason
</code_context>
<issue_to_address>
**Correct 404 response fails assertion**
When the handler correctly returns a 404 with the distribution message in the response body, `test_empty_distribution_returns_404` fails at line 48: `requests.Response.reason` is the HTTP status phrase (`Not Found`), not the response body containing the distribution message, so the assertion rejects the correct 404.
Check `response.text` for the distribution message instead of `response.reason`.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: pulp_service/pulp_service/tests/functional/test_content_handler.py:48
| response = requests.get(f"{distro.base_url}missing/path", timeout=30) | ||
|
|
||
| assert response.status_code == 404, response.text | ||
| assert "Distribution is not pointing to" in response.reason |
There was a problem hiding this comment.
🟡 Medium · Correct 404 response fails assertion
When the handler correctly returns a 404 with the distribution message in the response body, test_empty_distribution_returns_404 fails at line 48: requests.Response.reason is the HTTP status phrase (Not Found), not the response body containing the distribution message, so the assertion rejects the correct 404.
Check response.text for the distribution message instead of response.reason.
Prompt for AI agents
In `pulp_service/pulp_service/tests/functional/test_content_handler.py` at line 48:
**Correct 404 response fails assertion**
When the handler correctly returns a 404 with the distribution message in the response body, `test_empty_distribution_returns_404` fails at line 48: `requests.Response.reason` is the HTTP status phrase (`Not Found`), not the response body containing the distribution message, so the assertion rejects the correct 404.
Check `response.text` for the distribution message instead of `response.reason`.
Problem
Production content app returns 500 instead of 404 for distributions that have no repository, publication, or remote.
GlitchTip PULP-PROD-5J2: 1,433 events since 2026-11-02, still firing.
Root cause
Patch
0080-Optimize-read-only-content-queries.patchused a bare_as the throwaway target of three tuple unpacks insideHandler._match_and_stream:Assigning
_anywhere in a function makes it a function-local name, shadowing gettext's_. A distribution with nothing configured never executes any of those unpacks, so the later call is unbound:Result: 500 instead of
PathNotResolved(404). Triggered in prod by stale COPR pass-through distributions (public-copr*domains), which is why directory listings under those paths fail.A second latent defect came from the same shadowing:
:1136in theexcept ClientResponseErrorbranch would raiseTypeError: 'QuerySet' object is not callablewhenever_was bound by an earlier unpack, reporting upstream fetch failures as a misleading 500. Both go away with the rename.Change
images/assets/patches/0080-...patch: rename the discard target to_lazy_querysetin all three unpacks.pulp_service/tests/functional/test_content_handler.py: regression test — a distribution with no repository/publication/remote must return 404 with the "Distribution is not pointing to" reason. This path was previously unreachable in CI, which is why the patch passed review.CHANGES/2717.bugfix.Validation
_match_and_streamno longer stores to_(AST check) and still loads it only for gettext at 1136/1142.ruff format+make lint-diffclean.Fixes PULP-2717
Assisted-by: Opencode (DeepSeek-V4.1-Flash-1017)
Summary by Sourcery
Fix content handler error handling for distributions with no configured content source.
Bug Fixes:
Tests: