Skip to content

docs: move the examples off Flask imports - #764

Merged
uniqueg merged 3 commits into
devfrom
docs/753-examples-off-flask
Nov 12, 2026
Merged

uniqueg merged 3 commits into
devfrom
docs/753-examples-off-flask

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Summary

  • The petstore examples no longer import Flask: the access-control example takes the request path and path parameters from foca.context.current_request(), both examples return ("", 204) instead of make_response(), and docstrings name foca.errors.NotFound.
  • FOCA's CI and pre-commit hook run ast-grep scan --error=flask-import, so Flask imports in examples/** fail the check. The shared rule file stays a warning for apps that copy it.
  • Contributing guide updated.

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 branch
  • ast-grep test --skip-snapshot-tests: 9 passed
  • pytest -m "not mongodb": 4811 passed, 2 skipped (incl. the 11 tests/examples tests that assert 204 on delete)
  • ruff check, ruff format --check, mypy: clean
  • adversarial-reviewer: no findings; quality-reviewer: 4 lows, 2 fixed (comment wrap, docs wording)

Declined review findings

  • --error=flask-import is 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.md shows make_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:

  • Update the petstore examples to use FOCA-native request context, errors, response helpers, and plain return values instead of Flask APIs.
  • Preserve and verify pet-not-found responses with pet-specific error details in the integration suite.

Enhancements:

  • Enforce Flask-import detection as an error for examples in CI and pre-commit while retaining warning behavior for applications using the shared rule.

CI:

  • Make CI and pre-commit fail when Flask imports are introduced in the examples.

Documentation:

  • Update contributor guidance to document the stricter Flask-import checks and FOCA-native example conventions.

Tests:

  • Add integration coverage for the petstore unknown-pet 404 response and its mapped details.

uniqueg and others added 2 commits November 12, 2026 09:15
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
@sourcery-ai

sourcery-ai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Update 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.

  • examples/petstore-access-control/controllers.py L16-176 (7 small edits)

Use FOCA’s problem-response helper to return pet-specific details for unknown pets, and remove Flask response construction from the petstore controller.

  • examples/petstore/controllers.py L83-89 (+6 small edits)

Configuration

Make Flask imports in the examples fail CI and pre-commit while keeping the shared ast-grep rule configured as a warning for applications.

  • .ast-grep/rules/flask-import.yml L24-26
  • .github/workflows/ci.yml L138-140
  • .pre-commit-config.yaml L55-59

Documentation

Document 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.

  • docs/contributing/index.md L455-459

Tests

Add an integration test asserting that an unknown pet’s 404 response includes its identifier in the detail and petId fields.

  • tests/integration_tests.py L143-151

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (93e9721) to head (39f700e).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #764   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           74        74           
  Lines         9472      9472           
=========================================
  Hits          9472      9472           
Flag Coverage Δ
test_unit 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 12, 2026 09:32
@sourcery-ai

sourcery-ai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Linked issues

Checked at commit 39f700e

#753 docs: move the examples off Flask imports · 2 of 2 met

# Requirement Status Notes
1 Move the examples to foca.context, foca.errors and problem_response. ✅ Met The access-control controller uses current_request(); the examples use FOCA NotFound errors, and the petstore controller builds the unknown-pet response with problem_response().
2 Make the flask-import rule an error for examples/**. ✅ Met The rule targets examples/**, and CI and pre-commit run ast-grep scan --error=flask-import.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread examples/petstore/controllers.py Resolved
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
@uniqueg
uniqueg merged commit 775011e into dev Nov 12, 2026
57 of 58 checks passed
@uniqueg
uniqueg deleted the docs/753-examples-off-flask branch November 12, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs: move the examples off Flask imports

1 participant