Pylons/webob — Issue #5: NilAccept.best_match([], default_match="foo") broken
Author: cwebber
Created: 2011-10-18 20:17:54+00:00
State: open

Calling NilAccept.best_match([], default_match="foo") is broken.

I've created a pull request here to fix the issue:

https://github.com/Pylons/webob/pull/4

You might argue that this is a feature or that it's at least known... the previous test had a comment along the lines of:

# default_match has no effect on NilAccept class

However it seems to me that looking from the code that this is a bug (why assign to the otherwise unused best_match? and any call of seemingly fitting arguments, such as an empty sequence for offers and something that actually exists for default_match, shouldn't raise an error as it was previously with an UnboundLocalError exception...). I think this fix is reasonable, even urgent... the recent release logs of webob noted:

"Accept.best_matches() is gone; use list(request.accept) or request.accept.best_match(..) instead (applies to all Accept-* headers) or similar with request.accept_language."

So this seems to encourage using request.accept.best_match(request.accept_language, 'en') or similar. Indeed, I did this in two of my projects as a fix and it wasn't until I ran the tests that I noticed that this means that if your browser isn't passing in a Accept-Language argument, your application will break with the solution offered by the recent release notes!

I think this patch should be applied and hopefully a 1.2b3 can be released as a stopgap fix..