jruizgit / rules

Durable Rules Engine
MIT License
1.16k stars 206 forks source link

Unary operator not working as expected with nested objects #285

Open rtybanana opened 4 years ago

rtybanana commented 4 years ago

The unary operator +/- for matching the existence (or non-existance) of a named item doesn't appear to work for nested objects.

For instance:

with ruleset('test'):
    @when_all(+m.item)
    def test(c):
        print('success')

post('test', {'item': 'not_nested'})
post('test', {'item': {'nested': 'true'}})

In the above code block, the first post is matched with the rule but the second is not for whatever reason and throws the following error, despite the condition seemingly being met

durable.engine.MessageNotHandledException: {'item': {'nested': 'true'}}

In a similar vein, the unary operator also doesn't work when testing the presence of the nested values, so the following condition also throws a similar error

    @when_all(+m.item.nested)

Is there any way round this? Or is it just not possible to do that?

jruizgit commented 4 years ago

Hi, thanks for reporting this issue. Let me debug the scenario and report back on my findings.

jruizgit commented 4 years ago

Hi, I have published a fix for this issue. Please use version 2.0.16