[reportlab-users] PageTemplate unexpectedly copies Frames from earlier PageTemplates

Nate Silva nate at desi.com
Mon Nov 30 19:23:16 EST 2009

I've been pulling my hair out and finally boiled it down to the following snippet. Is this a bug?

I create a PageTemplate and add some Frames to it. So far so good. Then I create a second PageTemplate. For some reason, it inherits all of the Frames that were assigned to the first PageTemplate.

This happens when I append frames:

template1 = Template(id='template1')

template2 = Template(id='template2')

# template2 now unexpectedly has TWO Frames: the one from
# template1 and the one that was added to template2.

The bug does not happen if I pass the Frames to the Template constructor:

template1 = Template(id='template1', frames=[Frame(...)])
template2 = Template(id='template2', frames=[Frame(...)])

# This works as expected. template1 and template2 each have one
# frame.

Here is a complete Python program that demonstrates the problem.

from reportlab.platypus import *

def main():
template1 = PageTemplate(id='template1')
template1.frames.append(Frame(0, 0, 10, 20, id='t1_f1'))
template1.frames.append(Frame(30, 40, 50, 60, id='t1_f2'))

template2 = PageTemplate(id='template2')
template2.frames.append(Frame(1, 1, 11, 21, id='t2_f1'))
template2.frames.append(Frame(32, 42, 52, 62, id='t2_f2'))

# I expect to see two frames, but there are actually four.
# All of the frames from template1 have been copied into
# template2.
print [f.id for f in template2.frames]

if __name__ == '__main__':


Test System #1: Mac OS X 10.6.2, Python 2.6.1 (64-bit), ReportLab 2.3
Test System #2: Debian Linux 5.0.3, Python 2.5.2 (64-bit), ReportLab 2.3


More information about the reportlab-users mailing list