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

Abierto
#599 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
20/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python, rust
Área
backend

Línea de trabajo

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.

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

Descripción

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.

Lenguaje dominante
Rust
Estrellas
70
Forks
13
Merge medio
14 h 4 min
PR fusionados (30 d)
25

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.

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.