-
Notifications
You must be signed in to change notification settings - Fork 251
Closed
Description
Describe the bug
When partially evaluating (ContextEval) an expression like groups.exists(t, t == id)
where id
is declared as an unknown pattern, CEL fails with no such attribute(s): id
.
To Reproduce
Check which components this affects:
- parser
- checker
- interpreter
Sample expression and input that reproduces the issue:
groups.exists(t, t == id)
Test setup:
package main
import (
"context"
"log"
"github.com/google/cel-go/cel"
"github.com/google/cel-go/checker/decls"
)
func main() {
env, err := cel.NewEnv(cel.Declarations(
decls.NewVar("groups", decls.NewListType(decls.Int)),
decls.NewVar("id", decls.Int),
))
exitOnErr(err)
pvars, err := cel.PartialVars(
map[string]any{
"groups": []int{1, 2, 3},
},
cel.AttributePattern("id"))
exitOnErr(err)
ast, iss := env.Compile(`groups.exists(t, t == id)`)
exitOnErr(iss.Err())
prg, err := env.Program(ast, cel.EvalOptions(cel.OptTrackState, cel.OptPartialEval), cel.InterruptCheckFrequency(100))
exitOnErr(err)
log.Println("calling prg.Eval")
_, _, err = prg.Eval(pvars)
exitOnErr(err)
log.Println("calling prg.ContextEval")
_, _, err = prg.ContextEval(context.Background(), pvars)
exitOnErr(err)
}
func exitOnErr(err error) {
if err != nil {
log.Fatalf("Error: %v", err)
}
}
Expected behavior
Both Eval
and ContextEval
should successfully evaluate the above program, but prg.ContextEval
fails with no such attribute(s): id
.
Additional context
It's only folded expressions that can't be partially evaluated by the ContextEval
method.
Metadata
Metadata
Assignees
Labels
No labels