[Zope3-dev] trigger persistence

Shane Hathaway shane@zope.com
Thu, 05 Sep 2002 17:40:09 -0400


Jeremy Hylton wrote:
> I've seen code that says this:
> 
>         self._registry = self._registry #trigger persistence, if pertinent
> 
> Wouldn't it be clearer to say this directly?
> 
>         self._p_changed = 1
> 
> Then there would be no mystery and no need for a comment.

"self._p_changed = 1" is probably better for another reason also: it 
makes it easier to "grep" for a nasty little bug.  If the 
"self._p_changed = 1" comes after the code that actually makes the 
change, and an exception occurs between the change and setting 
self._p_changed, ZODB may not know that it needs to re-load that object 
when it aborts.  The object could silently lose sync with the database.

I've never seen this actually happen, but I'm sure it'll bite someone. 
Put "self._p_changed = 1" before the code that makes the change, not after.

Shane