Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion backend/apps/datasource/api/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
Loading