Python Code Works in Script Console but not Reports

Has any one else had issues with code working in script console but fails when in an actual project. I am running this code below and it works in script console but fail when trying to generate a report. The part that is failing is checking if t> 0. I posted a more complete segment below. Any ideas would be greatly appreciated. It consistently fails if row 0 Tons = 0 and row 1, 2, 3, 4, or 5 have a value > 0.


list1 = []
times = ['1 AM', '2 AM', '3 AM', '4 AM', '5 AM', '6 AM', '7 AM', '8 AM', '9 AM', '10 AM', '11 AM', '12 PM', '1 PM', '2 PM', '3 PM', '4 PM', '5 PM', '6 PM', '7 PM', '8 PM', '9 PM', '10 PM', '11 PM', '12 AM']
		
query = '''SELECT [Time],
				  [Slabs],
				  [Tons],
				  [Therms],
				  [Excluded_Tons]
		   FROM DowntimeReportSlabs'''
		   
ds= system.db.runPrepQuery(query, [], 'IgnitionDB')
t = 0
for row in range(ds.getRowCount()):
	#appends datasets to display 4 tables on the report
	
	
	if row <= 5:
		#time = ds.getValueAt(row, 'Time')
		time = times[row]
		s = ds.getValueAt(row, 'Slabs')
		t = ds.getValueAt(row, 'Tons')
		#if t == 0:
		#	t = .1
		therm = ds.getValueAt(row, 'Therms')
		if t > 0:
			th = therm/t
		else:
			th = 0
		list1.append([time, s, t, th])
		
		#list1.append([time, s, t])

The script console is Vision Scope, while reporting is Gateway Scope. Data types can vary. You should find an error in the gateway logs when this attempts to run in your report. Please show use the error (formatted as code).