From 9e51e22936d47f47b48b8e65bb39a71bb909eb29 Mon Sep 17 00:00:00 2001 From: junjun Date: Mon, 20 Apr 2026 10:16:05 +0800 Subject: [PATCH] fix: The system reports an error when uploading an Excel file with null values --- backend/apps/datasource/utils/excel.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/apps/datasource/utils/excel.py b/backend/apps/datasource/utils/excel.py index acfbaed8..dd404435 100644 --- a/backend/apps/datasource/utils/excel.py +++ b/backend/apps/datasource/utils/excel.py @@ -35,7 +35,8 @@ def parse_excel_preview(save_path: str, max_rows: int = 10): "fieldName": col, "fieldType": infer_field_type(df[col].dtype) }) - preview_data = df.head(max_rows).to_dict(orient='records') + preview_df = df.head(max_rows).replace({pd.NA: None, float('nan'): None}) + preview_data = preview_df.to_dict(orient='records') sheets_data.append({ "sheetName": "Sheet1", "fields": fields, @@ -52,7 +53,8 @@ def parse_excel_preview(save_path: str, max_rows: int = 10): "fieldName": col, "fieldType": infer_field_type(df[col].dtype) }) - preview_data = df.head(max_rows).to_dict(orient='records') + preview_df = df.head(max_rows).replace({pd.NA: None, float('nan'): None}) + preview_data = preview_df.to_dict(orient='records') sheets_data.append({ "sheetName": sheet_name, "fields": fields,