[ZODB-Dev] "Advanced ZODB for Python Programmers" article: volatile example
vincent at nexedi.com
Mon May 24 07:59:50 EDT 2010
I think the example on volatile attributes given in "Advanced ZODB for Python
Programmers" article shows a bad practice.
From the article:
if hasattr(self, '_v_image'):
This should be rewritten as:
This solves cases where _v_ attribute gets garbage-collected between hasattr
call and "return" line. A way to make this obvious is to artificially set
object cache size to 0.
Note that another broken pattern would be to use code like:
the article advertises the right pattern (using a local variable for return):
I've been hitting problems with this code pattern many times in the past, and
should have written about it earlier.
More information about the ZODB-Dev