Skip to content

馃 Fix error handler resolution in mounted applications (Issue #1205) - #1523

Closed
cgmark101 wants to merge 1 commit into
bottlepy:masterfrom
cgmark101:master
Closed

cgmark101 wants to merge 1 commit into
bottlepy:masterfrom
cgmark101:master

Conversation

@cgmark101

@cgmark101 cgmark101 commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

Following the maintainer's feedback on the complexity and open design questions around modifying hook and error handler resolution for natively mounted applications, this PR document these limitations and details the recommended workaround (app.wsgi).

Changes

  • Updated the docstring of Bottle.mount() to note that hooks and custom error handlers of natively mounted sub-applications are bypassed.
  • Added a new subsection to docs/plugins/index.rst ("Hooks, Error Handlers and Application Mounting") explaining the behavior and providing an example of mounting via the sub-application's WSGI interface (app.wsgi) for full isolation.

AI Disclosure and Manual Review

This contribution was prepared with the assistance of the AI agent Antigravity (using Gemini 3.5 Flash).
The documentation changes were manually proofread and verified for formatting correctness.

License

I explicitly license all my contributions to this project as public domain.

@defnull

defnull commented Jun 24, 2026

Copy link
Copy Markdown
Member

This only solves half of the issue, as hooks are sill not considered. For a good and clean solution we need a more involved refactor, maybe turning the hook+error+cast behavior into a decorator so we can wrap the route callback with it (multiple times if needed). There is also the question of hooks should all fire, or only the inner-most hooks (as with plugins), for which I do not have a definite answer right now.

As a workaround you can always fall back to mounting app.wsgi which is the most isolated mounting method. Maybe this is not an implementation issue, but more a documentation issue?

- Update Bottle.mount() docstring to note that hooks and custom error handlers are not run on natively mounted sub-applications.
- Add detailed explanation and example using app.wsgi workaround to docs/plugins/index.rst.

ai-assisted-by: Antigravity, Gemini 3.5 Flash
License: I explicitly license this contribution as public domain.
@cgmark101

Copy link
Copy Markdown
Contributor Author

Hi! Thanks for the feedback.

I completely agree that a proper runtime fix would require a much more involved refactoring of how hooks, errors, and cast operations interact. As suggested, I have reverted the code changes and instead updated the documentation to address this:

  1. Added a note to the Bottle.mount() docstring explaining that hooks and custom error handlers on natively mounted sub-applications are bypassed, recommending the .wsgi interface if complete isolation is required.
  2. Added a new subsection under docs/plugins/index.rst ("Hooks, Error Handlers and Application Mounting") detailing this behavior with a concrete code example.

I've force-pushed the new commits and updated the PR description. Let me know if this looks good to you!

@cgmark101 cgmark101 closed this by deleting the head repository Jul 4, 2026
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.

2 participants