Skip to content

Commit 6ed6a93

Browse files
committed
Fix exception in logging query results if 'result_rows' was none
1 parent f025f71 commit 6ed6a93

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

src/DatabaseLibrary/query.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -816,26 +816,25 @@ def _log_query_results(self, col_names, result_rows, log_head: Optional[int] = N
816816
msg += f'<th scope="col" style="background-color: #505050; color: #fff;{cell_border_and_align}">{col}</th>'
817817
msg += "</tr>"
818818
table_truncated = False
819-
for i, row in enumerate(result_rows):
820-
if log_head and i >= log_head:
821-
table_truncated = True
822-
break
823-
row_style = ""
824-
if i % 2 == 0:
825-
row_style = ' style="background-color: var(--secondary-color, #eee)"'
826-
msg += f"<tr{row_style}>"
827-
msg += f'<th scope="row" style="color:{row_index_text_color}; background-color: {row_index_background_color};{cell_border_and_align}">{i}</th>'
828-
for cell in row:
829-
try:
830-
cell_string = str(cell)
831-
except TypeError as e:
832-
cell_string = f"Unable printing the value: {e}"
833-
msg += f'<td style="{cell_border_and_align}">{cell_string}</td>'
834-
msg += "</tr>"
835-
msg += "</table>"
836-
if table_truncated:
837-
msg += (
838-
f'<p style="font-weight: bold;">Log limit of {log_head} rows was reached, the table was truncated</p>'
839-
)
840-
msg += "</div>"
841-
logger.info(msg, html=True)
819+
if result_rows is not None:
820+
for i, row in enumerate(result_rows):
821+
if log_head and i >= log_head:
822+
table_truncated = True
823+
break
824+
row_style = ""
825+
if i % 2 == 0:
826+
row_style = ' style="background-color: var(--secondary-color, #eee)"'
827+
msg += f"<tr{row_style}>"
828+
msg += f'<th scope="row" style="color:{row_index_text_color}; background-color: {row_index_background_color};{cell_border_and_align}">{i}</th>'
829+
for cell in row:
830+
try:
831+
cell_string = str(cell)
832+
except TypeError as e:
833+
cell_string = f"Unable printing the value: {e}"
834+
msg += f'<td style="{cell_border_and_align}">{cell_string}</td>'
835+
msg += "</tr>"
836+
msg += "</table>"
837+
if table_truncated:
838+
msg += f'<p style="font-weight: bold;">Log limit of {log_head} rows was reached, the table was truncated</p>'
839+
msg += "</div>"
840+
logger.info(msg, html=True)

0 commit comments

Comments
 (0)