GoogleCloudPlatform / webapp2

webapp2 is a framework for Google App Engine
https://webapp2.readthedocs.org
Other
141 stars 63 forks source link

webapp.uri_for() fails with keyword argument set to zero #36

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. Add the follow route to your app:

  application = webapp.WSGIApplication([
      webapp.Route(r'/page/<model_id:\d+>', PageHandler, 'page'),
  ], debug=True)

2. Try to get the URI for this handler:

  webapp.uri_for('page', self.request, model_id=0)

Result:
Exception:
  File "/home/rogerta/Public/google_appengine/lib/webapp2/webapp2.py", line 1706, in uri_for
    return request.app.router.build(request, _name, args, kwargs)
  File "/home/rogerta/Public/google_appengine/lib/webapp2/webapp2.py", line 1224, in default_builder
    return route.build(request, args, kwargs)
  File "/home/rogerta/Public/google_appengine/lib/webapp2/webapp2.py", line 978, in build
    path, query = self._build(args, kwargs)
  File "/home/rogerta/Public/google_appengine/lib/webapp2/webapp2.py", line 1002, in _build
    name.strip('_'))
KeyError: 'Missing argument "model_id" to build URI.'

What is the expected output? What do you see instead?
Should get correct URI for handler.

What version of the product are you using? On what operating system?
I am using the webapp2 package provided with the google appengine SDK v1.6.0, 
running with python 2.7.  I believe this is webapp2 v2.3.

From what I see of the code, it seems that line ~1000 in webapp2.py:

  if not value:

should be instead:

  if value is None:

Original issue reported on code.google.com by ro...@tawacentral.net on 5 Dec 2011 at 11:51

GoogleCodeExporter commented 8 years ago
Ah, this was unexpected. But you are correct. Explicit None checking should 
solve it.

Thanks for the report. :)

Original comment by rodrigo.moraes on 5 Dec 2011 at 11:59

GoogleCodeExporter commented 8 years ago

Original comment by bquin...@google.com on 7 Dec 2011 at 3:17

GoogleCodeExporter commented 8 years ago
This issue was closed by revision 58cfeb9c718d.

Original comment by rodrigo.moraes on 7 Dec 2011 at 4:12