← Back to team overview

openerp-community team mailing list archive

Unmutable defaults

 

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. So please allow me to ask you all to change the code you contributed to the "community" and/or "extra-addons" branches. For example we should now change this
*def foo(...., context={},....):
   ....*
to this :
*def foo(...., context=None,....):
   # you should add this test only if the context is actually used
   if context is None:
       context={}
   ....
*
I humbly suggest you fix the trunk branch in priority, and fix the 5.0 branches only if you feel totally comfortable with the changes.

Please read https://bugs.launchpad.net/openobject-server/+bug/525808 for more detail.

Lionel, for Numérigraphe SARL
begin:vcard
fn;quoted-printable:=C3=89quipe informatique Initiatives - Num=C3=A9rigraphe
n:Sausin;Lionel
org;quoted-printable;quoted-printable:Num=C3=A9rigraphe - Initiatives;=C3=89quipe informatique
adr;dom:;;11 rue Hector Berlioz;Le Mans;;72021
email;internet:informatique@xxxxxxxxxxxxxxxx
tel;work:+33 2 43 14 30 42
tel;fax:+33 2 43 14 30 25
x-mozilla-html:TRUE
url:http://numerigraphe.com
version:2.1
end:vcard


Follow ups