Skip to content

Commit 8424dcb

Browse files
committed
refactor: Optimizing Excel header fields with too long prompts #1364
1 parent 5d60284 commit 8424dcb

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

‎backend/apps/datasource/api/datasource.py‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,17 @@ def inner():
588588
except Exception as e:
589589
raise HTTPException(500, f"{trans('i18n_ds_upload_error')}: {str(e)}")
590590

591+
max_identifier_len = 63
592+
for col in df.columns:
593+
col_bytes = str(col).encode('utf-8')
594+
if len(col_bytes) > max_identifier_len:
595+
raise HTTPException(
596+
400,
597+
f"{trans('i18n_ds_upload_error')}: "
598+
f"Sheet [{sheet_name}] column name '{col}' exceeds "
599+
f"{max_identifier_len} bytes (actual: {len(col_bytes)} bytes)"
600+
)
601+
591602
conn = engine.raw_connection()
592603
cursor = conn.cursor()
593604
try:
@@ -598,7 +609,7 @@ def inner():
598609
index=False
599610
)
600611
output = StringIO()
601-
df.to_csv(output, sep='\t', header=False, index=False)
612+
df.to_csv(output, sep='\t', header=False, index=False, na_rep='\\N')
602613

603614
query = sql.SQL("COPY {} FROM STDIN WITH CSV DELIMITER E'\t'").format(
604615
sql.Identifier(table_name)

0 commit comments

Comments
 (0)