[reportlab-users] Reusing flowables can cause problems
Christoph Zwerschke
cito at online.de
Thu Sep 14 16:19:44 EDT 2006
I just noticed a very nasty pitfall in ReportLab's Platypus, namely the
_postponed attribute of Flowables that may be set during the build
process. The problem arises if you do something like this:
spacer = Spacer(...)
doc = SimpleDocTemplate(...)
# build a document
doc.build([spacer, ..., spacer, ...])
...
doc = SimpleDocTemplate(...)
# build another document
doc.build([spacer, ..., spacer, ...])
During the first build process, the _postponed attribute may have been
sticked to the spacer, so that it will not behave correctly in the
second build process.
I noticed that the undocumented multiBuild method solves this problem by
doing the following after each build process:
#clean up so multi-build does not go wrong - the frame
#packer might have tacked an attribute onto some flowables
for elem in story:
if hasattr(elem, '_postponed'):
del elem._postponed
Maybe this loop should be run automatically at the beginning of the
build method instead?
Otherwise, it should be better documented that Flowables should not be
reused after they have gone through a build process.
-- Christoph
More information about the reportlab-users
mailing list