← Back to team overview

openerp-expert-framework team mailing list archive

Re: [Bug 747776] Re: [6.02] error opening crm categories

 

On Monday 11 April 2011, you wrote:
> Hmm,
> It's not worth to make a video showing me clicking on
> Sales/config/helpdesk/categories ... aynd there is no more server output
> than in the bug message.
> 
> the question is, why does
>         reads = self.read(cr, uid, ids, ['name', 'parent_id'], context)
> returns
> {'parent_id': False, 'name': u'Sales Department', 'id': 1}
> instead of
> [{'parent_id': False, 'name': u'Sales Department', 'id': 1}]
> 
> and why only in my installation ?

Well, this is a "dark corner" of the framework:
In the addons code, we meet both cases of
   res1 = obj.read(cr, uid, ids=4, ...)
and
   res2 = obj.read(cr, uid, ids=[1,2,3], ...)
(same with the browse(.., ids=?) one)

The de-facto definition of this function is that if you supply an int/long id, 
it returns a single dict result. If you supply anything else[1] (we expect 
list/tuple), it returns a list of dicts.
So, res1 = {'id': 4, 'foo': ...}
and res2 = [{'id': 1, 'foo': ...}, ... ]

I know the framework is not very consistent this way. You'd expect the 
function to return the same type of results. But the problem is that it's used 
so much (and is such a basic fn) that we cannot just change it. It would break 
the API in a way that all rest of the code needs to be adapted.


[1] in a twisted way, something that evaluates to an int may result in a list 
return. Most probably, however, it will bork because we'd iterate on it.