← Back to team overview

openerp-community team mailing list archive

Re: Unmutable defaults

 

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.

-- 
Olivier Dony

begin:vcard
fn:Olivier Dony
n:Dony;Olivier
org:OpenERP Belgium
adr;quoted-printable:;;Chauss=C3=A9e de Namur, 40;Grand-Rosiere;;1367;Belgium
email;internet:odo@xxxxxxxxxxx
x-mozilla-html:FALSE
url:www.openerp.com
version:2.1
end:vcard


Follow ups

References