Skip to content

Conversation

@sonephyo
Copy link
Contributor

@sonephyo sonephyo commented Nov 3, 2025

Summary of Changes

This PR fixes suffixed and normal responders to have consistent behavior by raising MethodNotFound when method_map is empty. This is to disable allowing empty resources by nature, as mentioned in Issue #2167.

Test cases related to Stonewall are an empty Resource, which contradicts, and therefore, is removed.
Test case test_ws_simulator_collect_edge_cases is updated to include on_websocket function.
Test case (test_custom_error_route_not_found) is introduced for testing an empty resource.

Related Issues

Closes #2167

Pull Request Checklist

This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. Reading our contribution guide at least once will save you a few review cycles!

If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing to do.

  • Applied changes to both WSGI and ASGI code paths and interfaces (where applicable).
  • Added tests for changed code.
  • Performed automated tests and code quality checks by running tox.
  • Prefixed code comments with GitHub nick and an appropriate prefix.
  • Coding style is consistent with the rest of the framework.
  • Updated documentation for changed code.
    • Added docstrings for any new classes, functions, or modules.
    • Updated docstrings for any modifications to existing code.
    • Updated both WSGI and ASGI docs (where applicable).
    • Added references to new classes, functions, or modules to the relevant RST file under docs/.
    • Updated all relevant supporting documentation files under docs/.
    • A copyright notice is included at the top of any new modules (using your own name or the name of your organization).
    • Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives.
  • Changes (and possible deprecations) have towncrier news fragments under docs/_newsfragments/, with the file name format {issue_number}.{fragment_type}.rst. (Run tox -e towncrier, and inspect docs/_build/html/changes/ in the browser to ensure it renders correctly.)
  • LLM output, if any, has been carefully reviewed and tested by a human developer. (See also: Use of LLMs ("AI").)

- Change from SuffixedMethodNotFoundError to MethodNotFoundError
- Added Indicators for the resource and suffix
- Stonewall related test cases removed
- Already covered by test_custom_error_route_not_found which tests that empty resources raise MethodNotFoundError
@codecov
Copy link

codecov bot commented Nov 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (49f0cb1) to head (746dabc).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2564   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           64        64           
  Lines         7860      7864    +4     
  Branches      1076      1077    +1     
=========================================
+ Hits          7860      7864    +4     

☔ View full report in Codecov by Sentry.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sonephyo sonephyo changed the title Bug/validate empty resources fix:validate empty resources for non suffix responders Nov 3, 2025
@vytas7 vytas7 changed the title fix:validate empty resources for non suffix responders fix: validate empty resources for non-suffix responders Nov 3, 2025
Copy link
Member

@vytas7 vytas7 left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution @sonephyo!

I think this looks good for most of it, however, Falcon is known for going to great lengths for avoiding breaking surprises. So I think we should just emit a warning for now, and actually start raising an error only in 5.0.

Also, we need a newsfragment to describe what has been improved or fixed.

Copy link
Member

@CaselIT CaselIT left a comment

Choose a reason for hiding this comment

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

great, but as mentioned let's start with warning

@sonephyo sonephyo force-pushed the bug/validate-empty-resources branch from 6d20382 to b92b496 Compare November 11, 2025 22:41
@sonephyo sonephyo requested review from CaselIT and vytas7 November 12, 2025 14:07
Copy link
Member

@vytas7 vytas7 left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good for most of it 💯

Just a couple of cosmetic nitpicks before merging (see inline).

f'{resource_name} and suffix: {suffix}'
)
else:
warnings.warn(
Copy link
Member

Choose a reason for hiding this comment

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

I think it emitting our flavour of DeprecationWarning would be more consistent with the behaviour and evolution of the framework so far. We could also expand the wording a bit, explaining that adding resources without any responders is deprecated, and it would result in an error in Falcon 5.0.

assert resource_misc.called
assert resource_misc.req.method == method

def test_methods_not_allowed_simple(self, client, stonewall):
Copy link
Member

Choose a reason for hiding this comment

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

Let's leave this stonewall test intact (until Falcon 5.0, that is), just assert with pytest.warns(...) that a deprecation warning was emitted by add_route below.

class EmptyResource:
pass

with pytest.warns(UserWarning):
Copy link
Member

Choose a reason for hiding this comment

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

If we leave the stonewall part, maybe this test becomes somewhat redundant. But, OTOH, it doesn't hurt.

async def test_ws_simulator_collect_edge_cases(conductor):
class Resource:
pass
async def on_websocket(self, req, ws):
Copy link
Member

Choose a reason for hiding this comment

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

Maybe adding an unrelated method (such as on_delete or whatever) would match the original intent of this test case better? (I.e., not having any on_websocket() responder.)

@@ -0,0 +1,3 @@
Resources without responder methods now emit a ``UserWarning`` for non-suffix responders.
Copy link
Member

Choose a reason for hiding this comment

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

We could expand the newsfragment a bit, telling a story what the inconsistency was, and how it was addressed.

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.

Different behaviour between suffixed responders and "normal" ones

3 participants