Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluating unchecked expressions in CEL-Java #276

Open
1 of 3 tasks
Frnd-me opened this issue Mar 20, 2024 · 1 comment
Open
1 of 3 tasks

Evaluating unchecked expressions in CEL-Java #276

Frnd-me opened this issue Mar 20, 2024 · 1 comment

Comments

@Frnd-me
Copy link

Frnd-me commented Mar 20, 2024

Describe the bug

In the README, under "Common Questions", it is written that:

Checking is an optional, but strongly suggested, step in CEL expression validation. It is sufficient in some cases to simply Parse and rely on the runtime bindings and error handling to do the right thing.

I believe there currently is no way around checking an expression before evaluation, as an expression must be checked before it can be turned into a program and evaluated. An attempt to create a program from an unchecked AST always results in an error "programs must be created from checked expressions".

Checking in turn requires declaring variables. However, in my particular use case, I cannot acquire a full list of variables to be used in expressions (there may be many, and acquiring variable values is costly, so I would only like to do this whenever required). I believe that the above should be achievable with an unchecked variable and CelVariableResolver.

It seems that this behavior deviates from CEL Go and also does not coincide with a similar question posted in the CEL Go group: https://groups.google.com/g/cel-go-discuss/c/PoyIrdFPwHM. Here, the possibility of evaluating unchecked expression is suggested. An (unrelated) Python implementation supports the same functionality: https://github.com/cloud-custodian/cel-python.

I file this as a bug as the current behavior seems to be conflicting with respect to the documentation.

To Reproduce

Check which components this affects:

  • parser
  • checker
  • runtime

When attempting to create a program from an unchecked AST:

var p = cel.createProgram(cel.parse("5").getAst()).eval();

Expected behavior

I expect to be able to evaluate the unchecked expression.

Additional context

None.

@l46kok
Copy link
Collaborator

l46kok commented Mar 20, 2024

Hi,

This limitation is documented here:

Presently, Java does not support parse-only evaluation

But this is certainly a gap in CEL-Java with respect to the CEL specification. It's something we're aiming to address in the future.

@TristonianJones TristonianJones changed the title [BUG] Evaluating unchecked expressions Evaluating unchecked expressions in CEL-Java Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants