-
Notifications
You must be signed in to change notification settings - Fork 888
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
Make proutes more readable and report more info. #1431
Conversation
Currently proutes doesn't report what request_method's are accepted and the print out has static padding defined so it becomes unreadable very quickly.
func_name was deprecated in Python 3
Very pretty! |
I like how this PR sets the column width according to the maximum length of an item in a column plus 5 spaces of padding, assuming I interpret it correctly. Nicely done! I'm still tentative about merging PRs with code, though, so I'll leave the merging to a senior dev. |
Is the request method so important? I've never written an app that used the request_method predicate on a route and it may be deceiving here when debugging to see ALL and not understand why you're getting a 404. Just wanted to bring this up, but the output is definitely much improved. |
@mmerickel I think its useful, we pretty much always use request_method on the route because you can have a RESTful API using PUT, POST, PATCH but utilize the same view for a lot of it |
On 18 Oct 2014, at 09:49, John Anderson [email protected] wrote:
+1 (and yes, this looks much better! :))= |
@sontek Oh? You don't use view predicates for that? |
@mmerickel Yeah, we have a mix of both ways. This PR is currently only pulling the request method from the view the routes are attached to, but it might make sense to pull from the route as well. For example, you could cause a conflict like this: from pyramid.view import view_config
from pyramid.response import Response
@view_config(route_name='home', request_method='POST')
@view_config(route_name='home', request_method='PUT')
def home(request):
return Response("Hello Moon!")
from pyramid.config import Configurator
def main(global_config, **settings):
config = Configurator(settings=settings)
config.add_route('home', '/', request_method='PATCH')
config.scan()
return config.make_wsgi_app() |
@mmerickel The latest commit makes it prefer the route request method over the view request method. That way it wont return a request method that isn't actually available. This makes a project like this work: from pyramid.view import view_config
from pyramid.response import Response
@view_config(route_name='home', request_method='POST')
@view_config(route_name='home', request_method='PUT')
@view_config(route_name='home', request_method='PATCH')
def home(request):
return Response("Hello Moon!")
@view_config(route_name='vacation', request_method='PUT')
def vacation(request):
return Response("Hello Moon!")
from pyramid.config import Configurator
def main(global_config, **settings):
config = Configurator(settings=settings)
config.add_route('home', '/', request_method='PATCH')
config.add_route('vacation', '/vacation')
config.scan()
return config.make_wsgi_app() This would return:
|
@sontek I'd use the wording |
@mmerickel This is like the most important 1.6 feature of all time. |
I'm fine with merging this as-is but under duress. Even in this system of guessing the request method from the route and then the view, there are still plenty of scenarios that this will improperly display a method for which I feel is deceiving to a new user of this utility. I'd be much happier without the request method in there at all or clearly delineating where the derived method column is coming from. |
@mmerickel Do you have an example where this wouldn't show the correct thing? I could definitely pull the request method out of this PR and make it separate so we can discuss it. But I tried to match the logic up with what Pyramid would do when resolving what methods to allow |
Well in Pyramid the route predicates and view predicates are completely separate, so user's can introduce subtle bugs like |
@mmerickel The way I solved this was by only returning methods that could be hit. So in your example PUT and POST would be shown but GET would not. I think its better to at least give the information that GET is not available, rather than masking it and making them wonder why they are getting the 404. |
In my example it's not possible to match request, you will always 404 in either route or view lookup for that route. Also routes can be attached to any view if |
You are right, I wrote up a few more conflict examples and made it work a little better:
But found that sometimes even the current implementation of Pyramid can't resolve what view is attached and returns "unknown", and so sometimes the information could be invalid. I'm still leaning towards it being useful "most of the time" versus not having it, but I'll re-work the PR without it and the submit a separate PR with request_method so we can discuss it more. |
This cleans up the conflict resolving a little more
Awesome! I think we should totally add the feature as long as it degrades into some sort of "can't do it cap'n" feedback rather than false information in those ambiguous cases. |
I'll close this one for now and think about request method a bit more. |
Currently proutes doesn't report what request_method's are accepted
and the print out has static padding defined so it becomes unreadable
very quickly.
Prior to this change proutes looked like this:
With this change it looks like this: