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

Abierto Apto para principiantes
#2,594 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 5 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
85/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
data

Línea de trabajo

El error está en read_file en packages/graphrag-input/graphrag_input/jsonl.py, donde text.splitlines() se usa para dividir los registros. Reemplaza esa división por una división solo en "\n y elimina un "\r" final por línea, manteniendo la numeración de líneas y el comportamiento de advertencias de omisión existentes. Añade una prueba con U+2028, U+2029 y U+0085 dentro de un valor de cadena y luego ejecuta las pruebas existentes del lector JSONL. Listo cuando esas filas se lean intactas y los archivos CRLF sigan analizándose.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
36.6k
Forks
3.9k
Merge medio
4 d 11 h
PR fusionados (30 d)
1

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/graphrag

Todos los issues de microsoft/graphrag

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.