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

Condition syntax sometimes evaluates the wrong branch #50

Open
sewi-cpan opened this issue Dec 6, 2023 · 0 comments
Open

Condition syntax sometimes evaluates the wrong branch #50

sewi-cpan opened this issue Dec 6, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@sewi-cpan
Copy link

false ? true.exists_one(i, false) : false raises *BoolType* object is not iterable.
Expected: The first false should skip the first branch of the condition and execute the "else" branch (the last false).

The CEL language definition says:

To get traditional left-to-right short-circuiting evaluation of logical operators, as in C or other languages (also called "McCarthy Evaluation"), the expression e1 && e2 can be rewritten e1 ? e2 : false. Similarly, e1 || e2 can be rewritten e1 ? true : e2.

This error doesn't happen for false ? 1/0 : true. This condition correctly skips the division by zero.

sewi-cpan added a commit to sewi-cpan/cel-python that referenced this issue Dec 6, 2023
[The CEL language definition](https://github.com/google/cel-spec/blob/master/doc/langdef.md#logical-operators) suggests:
> To get traditional left-to-right short-circuiting evaluation of logical operators, as in C or other languages (also called "McCarthy Evaluation"), the expression e1 && e2 can be rewritten `e1 ? e2 : false`. Similarly, `e1 || e2` can be rewritten `e1 ? true : e2`.

`cel-python` used to evaluate the full tree before deciding if a branch will be used or not. This PR only evaluates a branch if selected by the condition.

Fixes issue cloud-custodian#50
@slott56 slott56 mentioned this issue May 21, 2024
@slott56 slott56 self-assigned this May 21, 2024
@slott56 slott56 added the bug Something isn't working label May 21, 2024
kapilt added a commit that referenced this issue Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants