Sale: the style of uses of "context" is not consistent

Bug #535178 reported by Numérigraphe
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Status tracked in Trunk
Trunk
Fix Released
Low
Unassigned

Bug Description

In the sale module (trunk & 5.0), the context is sometimes used as a "named parameter" (browse (...,context=context) ), and sometimes as a "positional parameter" (browse (...,context) ).
This doesn't cause problem as long as the orm API doesn't change, but the style would be improved if that were made consistent.
In most modules we use "context=context" all the time and I support that.
Lionel

Changed in openobject-addons:
assignee: nobody → JMA(Open ERP) (jma-openerp)
importance: Undecided → Low
milestone: none → 5.2
status: New → Confirmed
Revision history for this message
JMA(Open ERP) (jma-openerp) wrote :

Hello Lionel,

I have made the appropriate changes and attached the patch.

Would you please apply and let us know.

Thank you.

Revision history for this message
Numérigraphe (numerigraphe) wrote :

Thank you JMA for your dedication.
I can see you add a default context to some function: I humbly suggest you use None instead of {}, and evaluate the risk for side effects. Please read bug 525808 for more information.
Also, I can still see places where the context is not passed through to the ORM: maybe this is an occasion to improve on this issue. Here is one example, there are probably many others:
_amount_all(self, cr, uid, ids, field_name, arg, context):
        res = {}
        cur_obj = self.pool.get('res.currency')
        for order in self.browse(cr, uid, ids): # <-- context missing here
Thanks again.
Lionel.

Revision history for this message
JMA(Open ERP) (jma-openerp) wrote :

Hello Lionel,

Here is an improved version of the patch.

We thank you for your feedback.

Revision history for this message
Numérigraphe (numerigraphe) wrote :

Thank you JMA. I think Xavier (Open ERP) will object to the systematic tesing of the context - maybe you could have him review the patch?

Revision history for this message
JMA(Open ERP) (jma-openerp) wrote :

Hello,
It has been fixed by : mso@mso-20100413103539-f73if06mhbqyanvv
Thanks.

Revision history for this message
xrg (xrg) wrote : Re: [Bug 535178] [NEW] Sale: the style of uses of "context" is not consistent

On Tuesday 09 March 2010, you wrote:
> In most modules we use "context=context" all the time and
> I support that. Lionel

++

We should really try to have context as a named parameter in our code. Helps
avoid a very common bug.

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.