[Bug]: JSONLinesFileReader drops rows containing U+2028, U+2029 or U+0085 (uses str.splitlines)

オープン 初心者向け
#2,594 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 5 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
85/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
data

調査の方向性

バグは packages/graphrag-input/graphrag_input/jsonl.py の read_file にあり、レコードの分割に text.splitlines() が使われています。この分割を "\n のみでの分割に置き換え、各行末の "\r" を取り除いてください。既存の行番号付けとスキップ警告の動作は維持します。文字列値の中に U+2028、U+2029、U+0085 を含むテストを追加し、既存の JSONL リーダーのテストを実行してください。これらの行が壊れずに読み込まれ、CRLF ファイルも引き続き解析できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Do you need to file an issue?
  • I have searched the existing issues and this bug is not already filed.
  • My model is hosted on OpenAI or Azure. If not, please look at the "model providers" issue and don't file a new one here. (Not applicable: the bug is in the input reader, before any model call.)
  • I believe this is a legitimate bug, not just a question. If this is a question, please use the Discussions area.
Describe the bug

JSONLinesFileReader.read_file splits the file with text.splitlines() (jsonl.py#L38). Python's str.splitlines() also breaks on U+2028 (LINE SEPARATOR), U+2029 (PARAGRAPH SEPARATOR) and U+0085 (NEXT LINE). JSON Lines uses only \n as the record separator, and those three characters are valid unescaped inside JSON strings. A valid row containing one of them is therefore cut into two fragments, neither of which parses. Each fragment is logged as Skipping malformed JSONL row in <path> at line N, so that row is dropped from the input (the rest of the file is still read), and the only trace is a warning.

(Side note: splitlines() also splits on \x0b, \x0c, \x1c, \x1d and \x1e. Those are control characters that must be escaped in JSON, so they cannot occur unescaped in a valid row and are not part of this bug.)

Steps to reproduce

File x.jsonl, where the first row contains a raw U+2028 between a and b (shown here as <LS>):

{"text":"a<LS>b"}
{"text":"c"}
docs = await JSONLinesFileReader(storage=storage).read_files()
print([d.text for d in docs])   # ['c']   (expected ['a
b', 'c'])
# log: Skipping malformed JSONL row in x.jsonl at line 1
#      Skipping malformed JSONL row in x.jsonl at line 2

json.loads('{"text":"a
b"}') parses fine on its own. The same happens with U+2029 and U+0085.

Expected Behavior

Both rows are read. Split on "\n" only and strip a trailing "\r" for CRLF files.

GraphRAG Config Used
input:
  type: jsonl
Logs and screenshots
Skipping malformed JSONL row in x.jsonl at line 1
Skipping malformed JSONL row in x.jsonl at line 2
Additional Information
  • GraphRAG Version: 3.3.0 (graphrag-input at 5faaaf4f)
  • Operating System: macOS
  • Python Version: 3.11
  • Related Issues: #2424 / PR #2434 (JSONL reader skipped the whole file on blank lines). That is a different bug in the same function; the splitlines() loop appears to have come in with that fix.

Suggested fix: for line_number, line in enumerate(text.split("\n"), start=1): line = line.rstrip("\r"), plus a test with U+2028 and U+0085 inside a string value.

主要言語
Python
スター
36.6k
フォーク
3.9k
平均マージ
4日 11時間
マージ済み PR(30日)
1

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/graphrag のほかの issue

microsoft/graphrag の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。