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

blueprint.route methods argument typo throws unclear exception #760

Closed
adamkal opened this issue Jun 4, 2013 · 11 comments
Closed

blueprint.route methods argument typo throws unclear exception #760

adamkal opened this issue Jun 4, 2013 · 11 comments

Comments

@adamkal
Copy link

adamkal commented Jun 4, 2013

route method takes *options which catches all keyword arguments and passes it further to *url_rule_class which -- in case of typo like 'method' instead of 'methods' -- leads to misleading exception:

[..]
File "/[..]/python2.7/site-packages/flask/app.py", line 943, in add_url_rule
  rule = self.url_rule_class(rule, methods=methods, **options)
TypeError: __init__() got an unexpected keyword argument 'method'
@Turbo87
Copy link
Contributor

Turbo87 commented Jun 4, 2013

why do you think that this exception is misleading? got an unexpected keyword argument 'method' sounds to me like exactly describing the problem if you supplied method instead of methods.

@mitsuhiko
Copy link
Contributor

That's hard to fix due to how they work :(

@adamkal
Copy link
Author

adamkal commented Jun 19, 2013

@Turbo87 the problem is that it does not lead you to a place in your code where the mistake is. A new flask user will have to go through the code (like I did) to understand what the problem was.
@mitsuhiko I know it is hard to do but maybe someday someone who does not know that will just fix that? ;)

@davissclark
Copy link

So how can I fix this issue? I'm new to Flask and Python and programming, and I'm baffled.

@Ceasar
Copy link

Ceasar commented Sep 24, 2014

@davisclark Use 'methods' as the keyword argument, i.e. @app.route(methods=['GET', 'POST']).

@davissclark
Copy link

Oh my god, that's incredible. A single route had been mistyped.

After 6 hours of searching line by line, I can't thank you enough.

@jyxt

This comment has been minimized.

@kkzxak47

This comment has been minimized.

@davidism
Copy link
Member

I don't see a practical way to do this sort of typo checking in a general way, and don't think it's useful enough to justify the complexity. PyCharm, and possibly other IDEs, detect the correct kwargs. If you're not using the IDE, you're in the same situation here as you would be with any other code that uses this pattern. If anyone has a good argument and suggestion for why and how this should work, please open a new issue.

@imdanielsp

This comment has been minimized.

@jakhax

This comment has been minimized.

@pallets pallets locked as resolved and limited conversation to collaborators May 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests