[reportlab-users] Bug Report: Default parameter closure bug in several Graphics and Platypus classes
Robin Becker
robin at reportlab.com
Wed Dec 2 05:13:37 EST 2009
Nate Silva wrote:
> SUMMARY
>
> On this list yesterday I complained about, and Tim Roberts identified, a bug that causes Frames to be duplicated between PageTemplates.
>
> See Tim Roberts' e-mail dated 30-Nov-2009 (US) / 01-Dec-2009 (EU).
>
> Here is part of PageTemplate.__init__:
.........
> FINDINGS
>
> The bug occurs anywhere an empty list [] default argument is assigned to an instance variable. These are in the latest Subversion (revision 3604):
>
> reportlab.graphics.shapes.Polygon (shapes.py:1208)
> reportlab.graphics.shapes.PolyLine (shapes.py:1230)
> reportlab.platypus.doctemplate.PageTemplate (doctemplate.py:246)
> reportlab.platypus.flowables.KeepInFrame (flowables.py:878)
> reportlab.platypus.flowables.FrameSplitter (flowables.py:1145)
> reportlab.platypus.flowables.DocIf (flowables.py:1288)
>
> SAMPLE CODE
>
>........
> http://gist.github.com/246511
>
> Regards,
> Nate
thanks for the report and search. This will be fixed today. These modules were
coded a long time ago and probably I (or whoever coded them) wasn't really
thinking hard enough about all the use cases.
I think I prefer to indicate the usage in the argument default so we'll probably
use something like
def __init__(.....,frames=[],....):
......
self.frames = frames or []
which makes the actual value new each time.
--
Robin Becker
More information about the reportlab-users
mailing list