Repository navigation
fix(decorator): do not cache error responses (#575) - #2
Merged
Merged
Conversation
Return Response objects with status >= 400 directly instead of encoding and caching them. A cached 404 could be served as HTTP 200 on a later request. Add a regression test for 404 and 500 responses, the changelog fragment, and update the migration/compatibility status.
Check only changed Python files with a minimal mypy config. The inherited strict config follows imports into modules with pre-existing errors; the full baseline is a follow-up.
Towncrier 22.12 imports pkg_resources, which current setuptools no longer exposes. Use towncrier 26 in the workflow and lockfile; the dev dependency is restricted to Python >=3.9.
Rename the fragment from 554 to 2 so Towncrier links to the fork PR instead of a non-existent fork issue. Keep the upstream credit in the fragment text.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Responseobjects with status codes >= 400.Motivation
A cached error
Responsecould be returned as HTTP 200 on a later request. This is the first behavior fix in the fork and is intentionally scoped to upstream long2ice#554/long2ice#575. Credit to RitiGrover for the upstream fix.Behavior change
Error responses (status >= 400) returned explicitly as
Responseobjects are delivered directly and are not stored in the cache. Successful responses keep the existing behavior.Scope
This fix covers explicitly returned
Responseobjects with status >= 400. It does not cover every FastAPI error mechanism, such as mutating the status code of an injectedResponse; those cases need separate tests and PRs.Tests
stabled47e66bbefore the fix:assert 200 == 404for the second request.pytest -q: 30 passed, 4 xfailed (strict; P0-05).diff-cover: 100% on the two changed runtime lines.twine check, artifact inspection: passed.n=1, 404n=2from the installed package.Compatibility
MIGRATION.mdandCOMPATIBILITY.md.Migration notes
See the “Error responses” row in
MIGRATION.md. No code changes are required.Changelog
changelog.d/2.bugfix.mdlinks to this PR in the generated changelog. The upstream credit to RitiGrover remains in the fragment text.Checklist
CI and tooling note
Two small CI/tooling fixes were required to make this PR checks green. They are isolated in separate commits and do not change runtime behavior:
pkg_resources, which current setuptools no longer exposes. The dev dependency is restricted to Python >=3.9.These are prerequisites for the changed-files gate and the changelog check. If preferred, they can be split into a separate tooling PR before merge.
Related