From robin at reportlab.com Sun Dec 21 05:59:49 2025 From: robin at reportlab.com (Robin Becker) Date: Sun, 21 Dec 2025 10:59:49 +0000 Subject: [reportlab-users] Error in table column sizing with Platypus In-Reply-To: References: Message-ID: Hi Andy, thanks for the report. It is a bug so perhaps this is a rare case as tests did not catch it. I have added a fix and another test. They will be in the release. On Sat, 20 Dec 2025 at 16:52, Andy Hagar wrote: > Hello! > > I recently ran into an issue with table column sizing. Initially, the > error message was for: > AttributeError: 'float' object has no attribute 'endswith' > > An example setup is below to show the error happening. > > To get to this code path, I happened to have the following in my table > using Platypus > -At least 1 entry in a row uses Paragraph for formatting > -Specifying colWidth with one entry using percentage "%" > -Data in columns causing total column width to exceed availableWidth > > The error occurs at line 940 in tables.py: > if w.endswith('%'): > > Watching at execution, w is indeed a float. > Just changing to using the already existing _endswidth(w,'%') function > does allow the pdf to build, but it is ignoring the "X%" specified. > > Changing line 940 and the following has it look at W where the actual "X%" > value exists, but also changes the calculation on line 941 to handle the > percentage calc (assuming it is meant to be a % out of 100). > > Current: > if w.endswith('%'): > W[colNo] = w = availWidth*float(w[:-1])/percentTotal > > Updated: > if _endswith(W[colNo], '%'): > W[colNo] = w = availWidth * float(W[colNo][:-1]) / 100 > > > This change works fine to a point. When you specify a large-ish % and have > columns that are "wide", other errors start showing up. For the below > script, 88 or higher % causes errors elsewhere. > > This error is already called out in > https://groups.google.com/g/reportlab-users/c/k7GS01u3jrU > Error: > TypeError: '>' not supported between instances of 'NoneType' and 'int' > > Caused by Line 440: > tallest = '(tallest row %d)' % int(max(rh)) > > Changing to: > tallest = '(tallest row %d)' % int(max([i for i in rh if i], default=0)) > > Next error: > ValueError: with > cell(0,0) containing > 'Header 1': flowable given negative availWidth=-0.779770753733942 == > width=11.220229246266058 - leftPadding=6 - rightPadding=6 > > > At this point, as I was changing the % for testing and errors started > getting out of my depth, I just said "don't use silly %" and went about my > business :) > > --- > > Example script to hit this code path: > > from reportlab.platypus import SimpleDocTemplate, Table, Paragraph > from reportlab.lib.pagesizes import letter > from reportlab.lib.styles import getSampleStyleSheet > > styles = getSampleStyleSheet() > > data = [ > ['Header 1', 'Header 2', 'Header 3'], > [Paragraph('Row 1, Col 1 wide data wide data wide data wide data', > styles['Normal']), 'Row 1, Col 2 wide data wide data wide data', 'Row 1, > Col 3 wide data wide data wide data'] > ] > > doc = SimpleDocTemplate("table_endswidth.pdf", pagesize=letter) > story = [] > > colwidths = [None, "20%", None] > table = Table(data, colWidths=colwidths) > > story.append(table) > doc.build(story) > -- Robin Becker -------------- next part -------------- An HTML attachment was scrubbed... URL: