browse_null should have __iter__ method to prevent looping problems

Bug #1172292 reported by Ronald Portier (Therp)
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Confirmed
Low
OpenERP's Framework R&D
OpenERP Community Backports (Server)
New
Undecided
Unassigned

Bug Description

When a method that is expecting a browse_record receives a browse_null record, a looping condition might occur, that will lead to a server becoming totally unresponsive, while CPU utilization goes to 100%.

We encountered the problem in a line like the next, where mail_message is supposed to be a browse_record:

if field in mail_message:

because mail_message is in fact a browse_null record, this will result in an endless loop. Well, theoretically not endless, but __getitem__ will be called with increasing index values, in an attempt to find the item with name 'field'.

Look at this discussion:

http://stackoverflow.com/questions/926574/why-does-defining-getitem-on-a-class-make-it-iterable-in-python

The fix is simple. Give browse_null the same __iter__ method as browse_record:

    def __iter__(self):
        raise NotImplementedError("Iteration is not allowed on %s" % self)

It might be argued that modules should not have problems where browse_null objects are treated as browse_record objects. However, it is better to have a clear exception when using a specific function in a module, than a problem hanging a server with no message at all.

Related branches

Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Low
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.