← Back to team overview

openerp-community team mailing list archive

Re: Unmutable defaults

 

On 03/12/2010 10:32 AM, Olivier Dony wrote:
On 12/03/10 09:56, Équipe informatique wrote:
Dear community,
It seems we have all made a quite common mistake in our python code -
using empty lists or dictionaries as default values for functions.
As it turns out, we should not have done that because that makes the
defaults mutable, which may provoke strange bugs, very hard to
reproduce.

Indeed, that is a common mistake in python, you should normally refrain
from using mutable objects as default values, as explained in the bug.


So please allow me to ask you all to change the code you contributed
to the "community" and/or "extra-addons" branches.

Now I beg to differ, I don't think this is a major problem for the
current codebase. In fact I would bet that I can spot 10 more important
issues with *way more side-effects* in any given module (extra,
community, even official addons) before coming to this one. A few
examples: direct use of the database cursor when the ORM can do it, SQL
injection vectors, etc.

We are going to put online a list of such anti-patterns + best practices
for OpenERP developement.

So yes, if you are proposing a patch, modifying code, or writing new
code, it's important to pay attention to that, to be on the safe side.
But going through the whole code to change it is definitely overkill, as
the actual side-effects are very rare in practice.
If you have spare time, fix the other issues first.

My $0.02.
Thank you Olivier,

I'm totally agree with you.

Stephane
--
Stephane Wirtel - "As OpenERP is OpenSource, please feel free to contribute."
Quality/Release Manager
Technical Project Manager
Tiny SPRL
40, Chaussee de Namur
B-1367 Grand-Rosiere
* Tel: +32.81.81.37.00
* Fax: +32.81.73.35.01
* Web: http://www.openerp.com
* Planet: http://www.openerp.com/planet/
begin:vcard
fn:Stephane Wirtel
n:Wirtel;Stephane
org:OpenERP - Tiny sprl
adr;quoted-printable;quoted-printable:;;Chauss=C3=A9e de Namur, 40;G=C3=A9rompont;;1367;Belgium
email;internet:stw@xxxxxxxxxxx
title:Developer
tel;work:+32.81.81.37.00
note;quoted-printable:OpenERP is an Open Source enterprise management software=0D=0A=
	=0D=0A=
	http://www.openerp.com
x-mozilla-html:FALSE
url:http://www.tiny.be
version:2.1
end:vcard


References