Open sgendre opened 1 week ago
Hi @sgendre, thank you for opening this issue!
This expression is failing because CEL Playground disables mixed types for lists and maps.
It's being explicitly disabled by setting cel.HomogeneousAggregateLiterals()
and cel.ValidateHomogeneousAggregateLiterals()
options.
These options are set to follow the same configuration as Kubernetes.
Note, it's still possible to have mixed types when provided as input variable (right text area).
You can also define your CEL environment without these options. Here’s a version without them: https://heterogeneous-aggregates.cel-playground.pages.dev/ Available starting from this PR: https://github.com/undistro/cel-playground/pull/99.
Question
Hi, I am playing with playground to scope what is achievable or not with CEL and to spot what is valid CEL syntax or not.
Further Information
I try to implement an expression that return an object base on name This example is for simplicity purpose only. input:
person: name: 'sam'
expression KO
person.name == 'sam' ? { 'status': 'adult', 'age': 39} : { 'status': 'unknown', 'age': 0}
is failing to compilebut as soon as I change "age" and "adult" properties to string expression OK
person.name == 'sam' ? { "status": "adult", "age": "39"} : { "status": "adult", "age": "0"}
it compiles and is evaluatedand even inconsistent object shape return is fine as long as all properties does have the same type expression OK2
person.name == 'sam' ? { 'status': 'adult', 'age': '39'} : { 'status': 'unknown'}
Why is there such constraint?
You can play directly with
https://playcel.undistro.io/?content=H4sIAAAAAAAAA51TTUvDQBD9K2M8RKG2gicDRUQKflQrioiQy9hM08Xd2bAfrUX6351Ng6WHipgc8rIz897bmd2vbEo6K7LBAF5JT60hCBbCnOBqNIZHjava2cjVQcmSsrsGygMyKA7kcBrUgoTj%2FdJ7Mu96BY1dkqMKiBfKWTbEIXHTZ6OtI6msEian2shShflG1xpjGUafjSPvlcAxch2xJjgS%2FeN%2BctK6OYFXpwLBykbXWqNtzVyku6QXTy0xOkKQUMJeVQQz68R8EwNUGLAnGN4u78cgy7fPk4cUNxg6lsfEDPlT5LzdxQJ1xD3iWKNiH1qlrUBHNOr2n%2BqmVmuSzkmNnQkDmkaT74z5RjlMsbJ9pVjG0yjdrsHdpGRpnrfcZ5SpDYeQezQ5XMCXoIAh%2BryAHKuoQ94TUJP8n52vodjNiPzBdsnbnFNYd4KTu%2FT5u8xe7v8S%2FnjKz85%2FYc96WerwTeq1HOZDuJbxp%2BO5O4E9E%2B4ncxtPRckgT3JWbHyVLOTGViS86aqsvwHRXEQqMgMAAA%3D%3D
Screenshots
System Information
Additional Context
I dont know if the issue is specific to cel-playground or to the underlying used implementation
Thank for your time or for that online tool, it is so helpful to ramp-up 👍