Schema consistency errors have no field in Python

Aperta Adatta ai principianti
#378 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, typescript

Direzione di ricerca

Leggi src/selfgraph/schema.py nella sezione intorno a Schema._check_consistency, poi esamina src/selfgraph/models.py intorno a validation_error. Confronta la gestione dei percorsi in TypeScript in typescript/src/schema.ts. Riproduci i casi elencati e verifica se ogni errore Python espone lo stesso percorso field di TypeScript. Il lavoro è completato quando tutti gli errori di coerenza includono il percorso dell’errore, mantenendo invariati codice e messaggio.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Schema errors found by the cross-type consistency checks have the same code and message in both SDKs, but Python leaves field empty while TypeScript sets it to the path at fault. AGENTS.md asks for the same code, field, and hint for the same failure on every surface and in both SDKs, and agents use field to find what to change.

Tested at 04862c4 (current main), Python 3.14 and Node 26.12.

Reproduce
from selfgraph import Schema
from selfgraph.errors import SelfGraphError

for spec in [
    {"entities": [{"name": "Person"}, {"name": "Person"}]},
    {"entities": [{"name": "Employee", "parent": "Persn"}]},
    {"entities": [{"name": "Person"}], "relations": [{"type": "WORKS_AT", "to": {"types": ["Company"]}}]},
    {"relations": [{"type": "KNOWS"}, {"type": "knows"}]},
    {"relations": [{"type": "X", "from": {"max_count": 0}}]},
]:
    try:
        Schema.model_validate(spec)
    except SelfGraphError as e:
        print(e.code, e.field, str(e))
message Python field TypeScript field
invalid schema: entities[1].name: duplicate entity type 'Person' None entities[1].name
invalid schema: entities[0].parent: unknown type 'Persn' None entities[0].parent
invalid schema: relations[0].to.types[0]: unknown type 'Company' None relations[0].to.types[0]
invalid schema: relations[1].type: duplicate relation type 'knows' None relations[1].type
invalid schema: relations[0].from.max_count: must be >= 1 None relations[0].from.max_count

Errors from single-field checks (for example a non-string name) already carry a field in both SDKs; only these consistency checks lose it.

Cause

Schema._check_consistency (src/selfgraph/schema.py:204) is a model_validator(mode="after") that raises ValueError with the path written into the message text (for example :214, :232, :254, :264, :269). Pydantic records such an error at the model level with an empty location, so validation_error (src/selfgraph/models.py:371), which takes field from the first issue's location, gets nothing.

TypeScript's Schema (typescript/src/schema.ts:96-99) adds the same problem as an issue with an explicit path, which is where its field comes from. Raising the consistency errors with their location in Python, as a PydanticCustomError placed at that path or by setting field directly, would give the same field as TypeScript.

Lingua principale
TypeScript
Stelle
173
Fork
58
Merge medio
6h
PR unite (30g)
120

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di hydra-db/selfgraph

Tutte le issue di hydra-db/selfgraph

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.