Skip to content

fix(dataset): accept empty/single-row backup CSV import (#7491) - #7590

Merged
c121914yu merged 2 commits into
labring:mainfrom
skyzhao1223:fix/7491-dataset-empty-csv-import
Aug 25, 2026
Merged

fix(dataset): accept empty/single-row backup CSV import (#7491)#7590
c121914yu merged 2 commits into
labring:mainfrom
skyzhao1223:fix/7491-dataset-empty-csv-import

Conversation

@skyzhao1223

Copy link
Copy Markdown
Contributor

问题

Issue #7491:知识库导出分块后,用模板导入和备份导入都失败(私有部署 4.14 / 4.15 均存在)。

根因

导出方(projects/app/src/pages/api/core/dataset/exportAll.tscollection/export.ts)在以下场景会生成只有表头(或仅一行数据)的 CSV:

  • 知识库为空(无数据行)
  • 知识库只有单条分块数据

此时 papaparse 无法从多行数据推断分隔符,会抛出 Delimiter / UndetectableDelimiter提示性错误(数据本身未损坏)。而 parseDatasetImportFile 将任何 errors.length > 0 一律视为内容非法直接 reject,导致这些导出的备份无法重新导入。

修复

packages/service/core/dataset/importFile.tsPapa.parse 增加 skipEmptyLines: 'greedy':

  • 规避空数据/单行数据导致的 UndetectableDelimiter 提示性错误
  • 仍然保留对真实结构错误(如 MissingQuotes 引号未闭合)的拒绝行为

测试

  • 新增 3 个用例:空数据集备份(header-only CSV)、无结尾换行的 header-only CSV、单条数据行 CSV
  • 已验证:修复前 2 个新增用例失败,修复后全部通过
  • packages/service 全量测试:330 文件 / 3897 测试通过,无回归
  • eslint 通过

@cla-assistant

cla-assistant Bot commented Aug 25, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cla-assistant

cla-assistant Bot commented Aug 25, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


zhaotian1 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

When a dataset has no data rows (or a single chunk), the exporter
(exportAll.ts / collection/export.ts) generates a header-only or
one-line CSV. papaparse then emits a Delimiter/UndetectableDelimiter
hint because it cannot infer the delimiter from multiple rows, which
made parseDatasetImportFile reject valid backups with
'Invalid dataset import content'.

Parse with skipEmptyLines: 'greedy' to skip that benign hint while
still rejecting real structural errors (e.g. MissingQuotes).
@pull-request-size pull-request-size Bot added size/L and removed size/S labels Aug 25, 2026
@c121914yu
c121914yu merged commit d3be83f into labring:main Aug 25, 2026
12 checks passed
@github-actions

Copy link
Copy Markdown

Build and publish successful - Preview fastgpt Image:

ghcr.io/labring/fastgpt-pr:fastgpt_a937fefb7bf33266c61039b34bc9f02c2162b60d

🕒 Time: 2026-08-25 22:13:41 (UTC+8)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants