falconry/falcon

Different behaviour between suffixed responders and "normal" ones

Open

#2.167 geöffnet am 10. Aug. 2023

Auf GitHub ansehen
 (7 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Python (925 Forks)batch import
buggood first issue

Repository-Metriken

Stars
 (9.293 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 2T 7h) (9 gemergte PRs in 30 T)

Beschreibung

I'm developing a generic resource with all the API operations (GET/POST collection, GET/PUT/PATCH/DELETE element). The idea is to reuse this component by passing a DAO object to make it truly generic. The idea is that all the methods should be disabled by some resources, and I did this with this kind of code (minimal reproduction):

import falcon

class GenericResource:
    def __init__(self, on_get_collection=True):
        if on_get_collection:
            self.on_get_collection = self._on_get_collection

    def _on_get_collection(self, req, resp):
        resp.media = {'message': 'on_get_collection'}


app = falcon.App()
res1 = GenericResource()
res2 = GenericResource(on_get_collection=False)

As I start gunicorn server, my app crashes:

falcon.routing.util.SuffixedMethodNotFoundError: No responders found for the specified suffix

At this point, the resource "res2" is useless because it has no methods, I know... but this happens when I disable all "collection" methods. If I remove the suffix='collection' I only get 405s on every request, like this:

import falcon

class NoneResource:
    pass


app = falcon.App()
app.add_route('/res3', NoneResource())
# the next route crashes...
# app.add_route('/res4', NoneResource(), suffix='collection')

The issue is easy to bypass by removing the "collection" add_route, but I still think that both routes /res3 (normal route) and /res4 (suffixed route) should behave the same way, with no methods available...

Contributor Guide