cloud-custodian / cloud-custodian/cel-python

CompiledRunner Functions Bug

Aperta
#145 4 commenti 0 reazioni 2 assegnatari Rivendicata da @Quantum0uasar Vedi su GitHub
bug
Lingua principale
Python
Stelle
174
Fork
40
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Hello,

First of all thanks for producing this library very useful for some applications I'm looking at right now.

I'm trying to use the CompiledRunner with some additional functions defined, short example below:

```
{
'lower': celpy.celtypes.FunctionType,
'upper': celpy.celtypes.FunctionType
}

def lower(lhs: celpy.celtypes.StringType) -> celpy.celtypes.StringType:
return celpy.celtypes.StringType(lhs.lower())

def upper(lhs: celpy.celtypes.StringType) -> celpy.celtypes.StringType:
return celpy.celtypes.StringType(lhs.upper())

env = celpy.Environment(annotations=declarations, runner_class=CompiledRunner)

rule = "size(items) == 1 && meta.device.lower() == 'tablet'"
ast = env.compile(rule)

prgm = env.program(ast, functions={
'lower': lower,
'upper': upper
})
prgm.evaluate({'items': [1,2,3], 'meta': {'device': 'tablet'}})
```

This works normally when using the InterpretedRunner, however with the compiled runner I get the following:

```
TypeError: CELEvalError(*('no such overload', , (' CELEvalError(*(\'undeclared reference to "name \\\'__main__\\\' is not defined" (in container ())\', , ("name \'__main__\' is not defined",))) and CELEvalError(*(\'undeclared reference to "name \\\'__main__\\\' is not defined" (in container ())\', , ("name \'__main__\' is not defined",)))',))) or CELEvalError(*('undeclared reference to "name \'__main__\' is not defined" (in container ())', , ("name '__main__' is not defined",)))
```

I dumped out the source from the compiled runner:

```
# conditionaland:
ex_2_l = lambda activation: celpy.evaluation.bool_eq(celpy.evaluation.function_size(activation.items), celpy.celtypes.IntType(1))
ex_2_r = lambda activation: celpy.evaluation.bool_eq(__main__.lower(activation.meta.get('device')), celpy.celtypes.StringType('tablet'))
ex_2 = lambda activation: celpy.celtypes.logical_and(celpy.evaluation.result(activation, ex_2_l), celpy.evaluation.result(activation, ex_2_r))
CEL = celpy.evaluation.result(base_activation, ex_2)

Internal error: CELEvalError(*('undeclared reference to "name \'__main__\' is not defined" (in container ())', , ("name '__main__' is not defined",)))
```

This also happens when you use a lambda rather than referencing a function.

Looks like this may not be referencing the function correctly? Happy to assist if you want to point me in the right direction for resolution, or if this is an error on my part please let me know.

Thanks

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.