TurboGears / tg2

Python web framework with full-stack layer implemented on top of a microframework core with support for SQL DBMS, MongoDB and Pluggable Applications
http://www.turbogears.org/
Other
803 stars 77 forks source link

Issues with @cached(type='memory') and no Accept-Language header #109

Closed GitHK closed 5 years ago

GitHK commented 5 years ago

With the following setup:

I guess it could still be present in other releases as well.

The below command works as expected:

curl http://localhost/api/cached_endpoint?version=2 -H "Accept-Language: en-US"

This generates the traceback you can see at the end:

curl http://localhost/api/cached_endpoint?version=2

Is it possible to have a fix for it? I know browsers already add these for you, but other libraries, like Android's Volley do not do this by default. Would it be possible to have a fix?

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/tg/wsgiapp.py", line 120, in __call__
    response = self.wrapped_dispatch(controller, environ, context)
  File "/usr/local/lib/python3.6/site-packages/tg/appwrappers/errorpage.py", line 63, in __call__
    resp = self.next_handler(controller, environ, context)
  File "/usr/local/lib/python3.6/site-packages/tg/appwrappers/mingflush.py", line 52, in __call__
    resp = self.next_handler(controller, environ, context)
  File "/usr/local/lib/python3.6/site-packages/tg/appwrappers/caching.py", line 54, in __call__
    return self.next_handler(controller, environ, context)
  File "/usr/local/lib/python3.6/site-packages/tg/appwrappers/session.py", line 71, in __call__
    response = self.next_handler(controller, environ, context)
  File "/usr/local/lib/python3.6/site-packages/tg/appwrappers/identity.py", line 47, in __call__
    return self.next_handler(controller, environ, context)
  File "/usr/local/lib/python3.6/site-packages/tg/appwrappers/i18n.py", line 68, in __call__
    languages.extend(map(sanitize_language_code, context.request.languages))
  File "/usr/local/lib/python3.6/site-packages/tg/caching.py", line 48, in __get__
    return self._get_value(obj)
  File "/usr/local/lib/python3.6/site-packages/tg/caching.py", line 39, in _get_value
    value = self.func(obj)
  File "/usr/local/lib/python3.6/site-packages/tg/request_local.py", line 78, in languages
    return self.languages_best_match(self._language)
  File "/usr/local/lib/python3.6/site-packages/tg/request_local.py", line 37, in languages_best_match
    items = [i for i, q in sorted(al._parsed, key=lambda iq: -iq[1])]
TypeError: 'NoneType' object is not iterable
amol- commented 5 years ago

That seems related to the version of WebOb that gets installed. In 2.4 that depends on newer WebOb that shouldn't be a problem anymore, but for older TG versions if TurboGears package is not installed first, pip might end up picking the wrong version.

Using TG 2.3.12 might partially improve the sitaution, but the real fix is to ensure your application directly depends on the right version of WebOb.