return new browse_null() instance if the select argument is False in BaseModel:browse()

Bug #1156884 reported by Daniel Hammerschmidt
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Confirmed
Medium
OpenERP's Framework R&D

Bug Description

BaseModel:browse() should check if the select argument is False and return browse_null int that case.

The current implementation does check if the argument is an int or long or a list and returns either a browse_record or a list of browse_record or browse_null as fallback.

In Python True and False are instances of bool which is an subclass of int in python 2.

In an on_change_handler if we get the id of an many2one-field (e.g. parent_id) the value is False if the field is not set. Giving this to self.pool.get('res.partner').browse() returns a browse_record with the id set to False respectively 0 (zero) which probably does not exist in the database.

We could check each and every time the value of the id before passing to browse but it might be easier to to this in browse().

[code]
partner = self.browse(cr, uid, parent_id)
if partner: # browse_null:__nonzero__() returns False
    do_something()
[/code]

instead of

[code]
if parent_id is not False:
    partner = self.browse(cr, uid, parent_id)
    do_something()
[/code]

Revision history for this message
Daniel Hammerschmidt (redneck) wrote :
Changed in openobject-server:
assignee: nobody → OpenERP's Framework R&D (openerp-dev-framework)
importance: Undecided → Medium
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.