On 12/02/2010 04:27 PM, Dan Fairs wrote:
I was wondering whether the bug still exists in Python 2.x because I take it 
only AttributeError and TypeError should be ignored while calling __len__ in 
list() -- if that's the case, the bug is definitely still present.

True - I'll give it a try in 2.7 when I have a moment to grab and build it. 
That doesn't help us that much though, as 2.6 (which I'm running on, 2.6.1 to 
be precise) is a supported version.

I just checked, it doesn't exist in 2.7...

Anyway, I propose to call len() on those iterators, if possible, before calling 
list() because otherwise all bugs in backends will be swallowed.

That makes sense. I'd considered proposing storing any exception raised in 
__len__ on an instance variable to be re-raised later; but your solution is 
better, as you'd get better tracebacks.

Should I raise a bug for this behaviour? Working up a test and patch should be 
straightforward for this one, if we agree it's a bug that needs fixing (even if 
it's a workaround for the underlying Python issue).

... so even though it's not a Python bug but a Python "feature" I find it rather annyoing that list(x) swallows all TypeErrors in x.__len__ -- think about all the cases in that TypeErrors are raised! Wrong number of arguments, unsupported objects passed as argument e.g. to str/dict/list methods, ...

Regarding the fact that the calls to list() in QuerySet.__len__ is the central point to backend invocation I'm strongly for special-handling this case.

Jonas

--
You received this message because you are subscribed to the Google Groups "Django 
developers" group.
To post to this group, send email to django-develop...@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to