Repository navigation
Fix mounted apps using the parent's error handlers (#1205) - #1546
Open
inchang-ing wants to merge 1 commit into
Open
inchang-ing wants to merge 1 commit into
inchang-ing wants to merge 1 commit into
Conversation
Resolves bottlepy#1205. A natively mounted Bottle app's routes are merged into the parent's router, so when a request hits a mounted route the parent's own _handle/_cast cycle runs. _cast resolved the error handler off self unconditionally, so an HTTPError raised inside a mounted app's route was always rendered through the parent's handler, even when the child had registered its own. Now _cast looks up the matched route's owning app (request.route.app) and prefers its error_handler. Errors with no attributable route (e.g. an unmatched URL) still fall back to the mount host's own handler. Adds test_mount_error_handler and test_mount_error_handler_parent_unaffected to test/test_mount.py. The full suite shows no new regressions (the only failing tests are pre-existing Windows CRLF/template artifacts).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1205.
A natively mounted Bottle app's routes are merged into the parent's
router, so when a request hits a mounted route the parent's own
_handle/_castcycle runs._castresolved the error handler offselfunconditionally, so anHTTPErrorraised inside a mounted app'sroute was always rendered through the parent's handler, even when the
child had registered its own.
Fix
In
Bottle._cast, whenoutis anHTTPError, look up the matchedroute's owning app via
request.route.appand prefer itserror_handler.Errors with no attributable route (e.g. an unmatched URL, where routing
never sets
request.route) still fall back to the mount host's ownhandler — so a parent's own routes are unaffected.
This is the same behavior the previously closed PRs #1523 / #1533 aimed
for, implemented at the
error_handlerselection point withouttouching routing or dispatch otherwise.
Test plan
test/test_mount.py: addedtest_mount_error_handler(mounted child'sown
error(500)handler wins for an error raised in its route) andtest_mount_error_handler_parent_unaffected(parent's own routes stilluse the parent's handler).
pytest test/): 358 passed. The only failures arepre-existing Windows CRLF / template artifacts unrelated to this change
(confirmed identical with and without this patch).