fix: resolve pointer exhaustion on upload rerun and TypeError float len on PDF export

This commit is contained in:
Silas Brito
2026-07-13 20:12:56 -03:00
parent ecdee26142
commit 17b849b89a
2 changed files with 40 additions and 22 deletions
+16 -4
View File
@@ -2,6 +2,18 @@ from fpdf import FPDF
import datetime
import hashlib
def clean_str(val, default="N/A"):
"""
Safely casts database records to strings, checking for None and float NaN.
"""
if val is None:
return default
# check if float NaN
if isinstance(val, float) and val != val:
return default
s = str(val).strip()
return s if s else default
class NetBackupMitigationPDF(FPDF):
"""
Sleek, brand-aligned A4 layout representing the Veritas dark tech design system.
@@ -151,12 +163,12 @@ def generate_mitigation_pdf(jobs_list, filter_name="Consolidated"):
fill_row = False
for j in failures_list:
jid = j['job_id']
client = j['client'] or 'N/A'
policy = j['policy'] or 'N/A'
client = clean_str(j['client'])
policy = clean_str(j['policy'])
code = j['exit_code']
reex = 'Reexecutado' if j['is_rerun_success'] == 1 else 'Pendente'
status = j.get('status', 'Pendente')
action = j.get('action_taken', '') or 'Nenhuma nota registrada.'
status = clean_str(j.get('status'), 'Pendente')
action = clean_str(j.get('action_taken'), 'Nenhuma nota registrada.')
# String safety trims
if len(client) > 20: client = client[:18] + '..'