rmyers / webapp-improved

Automatically exported from code.google.com/p/webapp-improved
Other
0 stars 0 forks source link

uri_for and Route.build only work in the context of a request #91

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I'm trying to use uri_for to generate URIs but I have scripts that run outside 
the context of a request. These scripts crash like this:

/python/lib/webapp2-2.5.2/webapp2.py", line 1731, in uri_for
    request = _request or get_request()
/python/lib/webapp2-2.5.2/webapp2.py", line 1719, in get_request
    assert getattr(_local, 'request', None) is not None, _get_request_error
AssertionError: Request global variable is not set.

I was wondering why a URL-building function would even depend on request 
context in the first place and found this:

        if full or scheme or netloc:
            netloc = netloc or request.host
            scheme = scheme or request.scheme

Seems like a very trivial thing relative to the dependency it adds.

I suggest making request optional in Route.build and being tolerant to its 
absence.

Original issue reported on code.google.com by d...@desmondbrand.com on 4 Jul 2014 at 12:36