~bitglue/openobject-server/fix-dh_installchangelogs

Viewing all changes in revision 3724.

  • Committer: Xavier Morel
  • Date: 2011-10-05 11:24:44 UTC
  • Revision ID: xmo@openerp.com-20111005112444-jcp9fw6pa36ahpsd
[IMP] raise error when iterating over browse_record

Python has an iteration fallback protocol: when iterating over an
object which does not define __iter__, if the object defines
__getitem__ it considers that it's a list, and invokes __getitem__
from index `0`.

This can be a problem in openerp in methods which expect an list of
ids but are only given a single id (not a singleton list), in that
case self.browse() will return a single browse_record (instea of a
list) and the method tries to iterate over it by calling
browse_record.__getitem__.

Problem is that browse_record.__getitem__ is pretty deep and does
little validation, so the error appears 3 frames below where the
actual issue is with a completely cryptic message of "KeyError: 0",
which makes the actual harder to track.

By raising an error immediately in browse_record.__iter__, this kind
of issues is much easier to handle, the stack points precisely to the
frame in error with a clearer message.

expand all expand all

Show diffs side-by-side

added added

removed removed

Lines of Context: