[ZODB-Dev] How to avoid shooting my foot

Andrew Kuchling akuchlin@mems-exchange.org
Mon, 7 Oct 2002 08:39:43 -0400


On Sun, Oct 06, 2002 at 04:59:13PM -0500, Jeff Bauer wrote:
>Q2: Is it usually easy to figure out when it happens,
>or is the problem difficult to track?  (If the latter,
>any war stories would be appreciated.)

It depends.  The problem is quickly spotted if you're using
short-lived processes, because the symptom is straightforward; you run
code that makes a change, and the code runs without errors but the
next process doesn't see any change.  

A long-running process such as a FastCGI or SCGI process can hide the
bug for a long while, though.  Objects are cached, so the change will
only be lost when the incorrectly modified object gets flushed from
cache, and that's unpredictable.  If the buggy modification is usually
combined with other modifications that dirty the object, the bug is
hidden until the usage pattern changes.

Another small risk is accidentally modifying an object that then gets
committed.  It's easy to get a list, call .sort() or reverse() on it
for some computation, and forget that you've just modified the list in
the database.  My preferred solution is to return a copy of the list
via an accessor, and provide .append_thing(), .remove_thing() methods
for changing the list.

--amk