Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route naming introspection always return "method" for method endpoints #1552

Closed
flxdot opened this issue Mar 25, 2022 · 0 comments · Fixed by #1553
Closed

Route naming introspection always return "method" for method endpoints #1552

flxdot opened this issue Mar 25, 2022 · 0 comments · Fixed by #1553

Comments

@flxdot
Copy link
Contributor

flxdot commented Mar 25, 2022

Discussion was done at https://gitter.im/encode/community. Bug was confirmed by @Kludex.

Description

methods don't get detected on is_function, then we assume that <object>.__class__.__name__ will give the right name (my_method on the example below) for it, but it actually gets the "method" name, which is wrong.

Unexpected behaviour seem to originate from:

if inspect.isfunction(endpoint) or inspect.isclass(endpoint):

Minimal example

from starlette.responses import JSONResponse
from starlette.routing import Route


async def my_function(request):
    return JSONResponse({'endpoint_type': 'function'})


class MyClass:
    def __call__(self, request):
        return JSONResponse({'endpoint_type': 'class'})


class MySpecialEndpointObject:
    async def my_method(self, request):
        return JSONResponse({'endpoint_type': 'method'})


endpoint_obj = MySpecialEndpointObject()
function_route = Route('/functionEndpoint', my_function)
class_route = Route('/classEndpoint', MyClass())
method_route = Route('/methodEndpoint', endpoint_obj.my_method)

assert function_route.name == "my_function"
assert class_route.name == "MyClass"
assert method_route.name == "my_method"  # AssertionError

Actual behavior

Value of method_route.name is "method".

Expected behavior

Value of method_route.name is "my_method".

It could also be "MySpecialEndpointObject_my_method". Reason here is to prevent ambiguity.

@flxdot flxdot changed the title Route naming of Route naming introspection always return "method" for method endpoints Mar 25, 2022
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 a pull request may close this issue.

1 participant