Skip to content

fix: undo changes of failed middlewares #313

Closed

Description

@uniqueg

Problem

Alternatives of a middleware step (custom.middlewares, a list of
lists) share one mutable request. MiddlewareHandler.apply_middlewares()
passes the same flask.Request to each alternative; an alternative that
changes the JSON body (request.json) and then raises leaves its partial
changes for the next alternative, which then works on a task that no one
intended (found in the plugin design review, plugin-architecture.md
2.1).

Proposal

Copy the body before each step; after a failed alternative, restore it
in place (middlewares change request.json in place, which Flask parses
once per request), so every alternative starts from the body as it was
before the step. The middleware interface stays as it is (the interface
change is #315).

Acceptance criteria

  • A test with an alternative that changes the body and raises,
    twice, before a working one: the result has only the working
    alternative's change (fails without the fix).
  • Docs (docs/middlewares.md): changes of failed middlewares are
    undone; middlewares change the body in place.
  • ruff, mypy, ast-grep, semgrep, pytest (100% coverage),
    mkdocs build --strict pass locally.

Verification (local)

ruff check, ruff format --check, mypy (77 files), ast-grep scan

  • rule tests, semgrep --config=.semgrep, coverage run -m pytest
    (1037 passed, 80 skipped: chart tests without helm and real-MongoDB
    tests; 100%), mkdocs build --strict. Not run: the Docker Compose smoke
    test and the MongoDB 7.0 matrix entry (CI runs them).

Dependencies

Open questions

  • None.

Activity

  1. added
    priority: medium
    status: in progress
    type: bug
    workload: hours
    on Oct 24, 2026
  2. removed
    status: in progress
    on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority: mediumtype: bugworkload: hours

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions