Skip to content

Commit 8cbf15a

Browse files
committed
fix: warning if cell cannot be set for Excel export
1 parent 6b4bd5e commit 8cbf15a

File tree

1 file changed

+7
-1
lines changed
  • backend/application/commons/services

1 file changed

+7
-1
lines changed

backend/application/commons/services/export.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import logging
23
from datetime import datetime
34
from typing import Any, Optional
45

@@ -9,6 +10,7 @@
910
from openpyxl import Workbook
1011
from openpyxl.styles import Font
1112

13+
logger = logging.getLogger("secobserve.commons")
1214

1315
def export_excel(objects: QuerySet, title: str, excludes: list[str], foreign_keys: list[str]) -> Workbook:
1416
workbook = Workbook()
@@ -40,7 +42,11 @@ def export_excel(objects: QuerySet, title: str, excludes: list[str], foreign_key
4042
value = str(getattr(current_object, key))
4143
if value and isinstance(value, datetime):
4244
value = value.replace(tzinfo=None)
43-
worksheet.cell(row=row_num, column=col_num, value=value)
45+
try:
46+
worksheet.cell(row=row_num, column=col_num, value=value)
47+
except Exception as e:
48+
logger.warning(f"Cannot set cell with type {type(value)}")
49+
logger.warning(str(e))
4450
col_num += 1
4551
row_num += 1
4652

0 commit comments

Comments
 (0)