Framework RecipesImplementation, failure path, check

Flask: preserve requirements through advanced agent edits

Work through Python examples of real application boundaries: Keep Flask request connections from leaking on error paths; Deduplicate a signed Flask webhook inside its state transaction. Each recipe includes implementation code, integration prerequisites, failure-path tests to add, a Perch rule, and the captured broken/fixed source checks.

Download the Flask rule pack ZIP · Inspect the YAML rules

Python

Keep Flask request connections from leaking on error paths

Flask application-context teardown runs even when a request raises. A request-scoped connection belongs on g and must be removed and closed there. Closing only at the end of the happy-path route misses exceptions and early responses.

Broken edit flagged · corrected edit passes

Python

Deduplicate a signed Flask webhook inside its state transaction

A provider may deliver an authenticated event several times. Signature verification establishes its origin; a unique receipt and a transaction establish whether this application already processed it. Neither check replaces the other.

Broken edit flagged · corrected edit passes

Use a correction as a saved requirement

Choose the failure you need to prevent, add the scoped rule to your repository, and check both the broken and corrected implementation. Ask your agent to inspect the finding, repair the code and recheck the same rule. Keep framework tests beside the model check.

Perch keeps the requirement beside the code. Reuse the named check during the agent’s next edit and in CI, with cached answers free on unchanged requests.

Official Flask documentation · All language and framework recipes