The stupidity of 'id' as a variable name (or stupidity of me)
16 September 2008
Both in Zope2 and in Django you need to work with attributes called
id. This is a shame since it's such a huge pitfall. Despite having done Python programming for so many years I today fell into this pitfall twice!! The pitfall is that
id is a builtin function, not a suitable variable name. The reason is that I was changing a complex app to use something called the
UUID as the indentifier instead of the
ID which happened to be a name of a primary key in a table.
This meant lots of changes and I tested and tested and kept getting really strange errors. I took the whole thing apart and put it back together when I discovered my error of checking if variable
id was set or not.
id, if undefined, defaults to the builtin function
id() which will always return true on
It's been a long day. I'm going home. Two newbie mistakes in one programming session. I'm sure I'm not the only one who's been trapped by this.