[Feature Request] A CEL rule naming a missing field is an EvaluationError, not a CompilationError

Aperta
#599 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
20/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, rust
Ambito
backend

Direzione di ricerca

The issue names the repro (this.missing == 1 on a message with only name) and the harness at test/conformance/test_conformance.py; start by running that harness with --strict_error to watch the custom_rules compilation/missing_field case fail. From there the work is in the Rust core's rule-compilation path, where each compiled rule needs to be type-checked against the message type (and rules/rule for predefined rules) and a check failure surfaced as CompilationError rather than deferred to evaluation. Done means the repro raises CompilationError and the conformance suite passes under --strict_error.

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

Descrizione

Description

A CEL rule that names a field the message doesn't have is accepted when its type is first validated, and every validation of the type then raises EvaluationError. The conformance case custom_rules compilation/missing_field expects a CompilationError. It passes because test/conformance/test_conformance.py runs the harness without --strict_error, which accepts a runtime error in place of a compilation error.

Since 2.0 the rules are evaluated by cel-cpp, which has a type checker, but the error shows that the expression isn't checked against the message type when it's compiled.

Steps to Reproduce

message BrokenRequest {
  option (buf.validate.message).cel = {
    id: "broken"
    expression: "this.missing == 1"
  };
  string name = 1;
}
import protovalidate
from gen.rules_pb import BrokenRequest

protovalidate.Validator().collect_violations(BrokenRequest(name="x"))

Expected Behavior

CompilationError, as protovalidate-go reports when the type is first loaded.

Actual Behavior

protovalidate.EvaluationError: error evaluating broken: no_such_field : missing, on every call.

Environment

  • protovalidate-py: 2.1.0
  • Python: 3.14
  • Protobuf Compiler & Version: protoc-gen-py

Possible Solution

Type-check each rule with cel-cpp's checker when it's compiled, declaring this (and rules/rule for predefined rules) as the message or rule type, and raise CompilationError for a check failure. Running the conformance harness with --strict_error would then hold the behaviour in place.

Additional Context

A typo in a rule is a schema error, but as an EvaluationError it looks the same as a failure that depends on the message's values, such as a division by a field that is zero. A caller that wants to refuse a broken schema at startup, for example by validating each request type once when a service starts, can't tell the two apart without matching error text. So a service with a typo in a rule starts and then fails every request of that type.

Lingua principale
Rust
Stelle
70
Fork
13
Merge medio
14h 4m
PR unite (30g)
25

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.

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.