From 8492f638ebeb6695f269619914e05a7a7fcc7d07 Mon Sep 17 00:00:00 2001 From: junjun Date: Mon, 14 Sep 2026 10:39:47 +0800 Subject: [PATCH] refactor: Optimizing Excel header fields with too long prompts #1364 --- backend/apps/datasource/api/datasource.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/backend/apps/datasource/api/datasource.py b/backend/apps/datasource/api/datasource.py index 2e1636c9..a7fb26b7 100644 --- a/backend/apps/datasource/api/datasource.py +++ b/backend/apps/datasource/api/datasource.py @@ -588,6 +588,17 @@ def inner(): except Exception as e: raise HTTPException(500, f"{trans('i18n_ds_upload_error')}: {str(e)}") + max_identifier_len = 63 + for col in df.columns: + col_bytes = str(col).encode('utf-8') + if len(col_bytes) > max_identifier_len: + raise HTTPException( + 400, + f"{trans('i18n_ds_upload_error')}: " + f"Sheet [{sheet_name}] column name '{col}' exceeds " + f"{max_identifier_len} bytes (actual: {len(col_bytes)} bytes)" + ) + conn = engine.raw_connection() cursor = conn.cursor() try: @@ -598,7 +609,7 @@ def inner(): index=False ) output = StringIO() - df.to_csv(output, sep='\t', header=False, index=False) + df.to_csv(output, sep='\t', header=False, index=False, na_rep='\\N') query = sql.SQL("COPY {} FROM STDIN WITH CSV DELIMITER E'\t'").format( sql.Identifier(table_name)