Repository navigation
docs: move the examples off Flask imports - #764
Conversation
The petstore examples take the request path and path parameters from foca.context.current_request(), document foca.errors.NotFound and return plain (body, status) tuples instead of make_response(). FOCA's CI and pre-commit hook now run ast-grep with --error=flask-import, so Flask imports in the examples fail the check; the shared rule file stays a warning for apps. Closes #753 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Reviewer's GuideAPIUpdate the access-control controller to read request data through FOCA, document FOCA’s not-found exception, and return a plain body/status tuple for deletion.
Use FOCA’s problem-response helper to return pet-specific details for unknown pets, and remove Flask response construction from the petstore controller.
ConfigurationMake Flask imports in the examples fail CI and pre-commit while keeping the shared ast-grep rule configured as a warning for applications.
DocumentationDocument that FOCA’s CI and pre-commit treat the shared Flask-import rule as an error for the examples and describe the FOCA-native example conventions.
TestsAdd an integration test asserting that an unknown pet’s 404 response includes its identifier in the detail and petId fields.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #764 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 74 74
Lines 9472 9472
=========================================
Hits 9472 9472
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Linked issuesChecked at commit 39f700e #753 docs: move the examples off Flask imports · 2 of 2 met
|
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="examples/petstore/controllers.py" line_range="73" />
<code_context>
Raises:
- werkzeug.exceptions.NotFound: The pet does not exist.
+ foca.errors.NotFound: The pet does not exist.
"""
db_collection = _get_collection()
</code_context>
<issue_to_address>
**Use problem_response**
The issue asks for the examples to use `problem_response`, but neither example calls it. The change updates the documented error type and replaces `make_response()` for successful deletes, but does not demonstrate or use `problem_response`.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and the access-control example now derives its policy path and resource-ID check from FOCA’s request context; if those values differ from Flask’s, an ownership check could apply to the wrong resource and allow an unauthorized deletion. Reverting restores the old check, but any records deleted while the wrong check was live would not be restored.
Blocking findings: examples/petstore/controllers.py:73
Unknown pets get a 404 naming the pet (detail and petId), built with problem_response(), with an integration test. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Summary
foca.context.current_request(), both examples return("", 204)instead ofmake_response(), and docstrings namefoca.errors.NotFound.ast-grep scan --error=flask-import, so Flask imports inexamples/**fail the check. The shared rule file stays awarningfor apps that copy it.No behaviour change for apps, so there is no migration note.
Verification
ast-grep scan --error=flask-import: exit 1 on dev (the two example imports), exit 0 on this branchast-grep test --skip-snapshot-tests: 9 passedpytest -m "not mongodb": 4811 passed, 2 skipped (incl. the 11tests/examplestests that assert 204 on delete)ruff check,ruff format --check,mypy: cleanDeclined review findings
--error=flask-importis duplicated in CI and pre-commit: kept, because the contributing guide names both and a consistency test would be more code than it saves.docs/preparing-for-asgi.mdshowsmake_response(...): that is the labelled "before" snippet, so it stays.Open questions
None.
Closes #753
🤖 Generated with Claude Code
https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Summary by Sourcery
Remove Flask dependencies from the petstore examples and enforce the framework-independent example conventions in development checks.
Bug Fixes:
Enhancements:
CI:
Documentation:
Tests: