[python] evaluate None type value
I'm having trouble figuring out how to effectively test against None type. I mean when a variable/dict-key has the value of None.
Here's a simple snippet
from durable.lang import *
jj = {'v': None}
with ruleset('getNone1'):
@when_all(-m.v)
def isNone_4(c):
print('isNone_4')
with ruleset('getNone2'):
@when_all(none(+m.v))
def isNone_3(c):
print('isNone_3')
# both post causes infinite loop
post('getNone1', jj)
post('getNone2', jj)
Both post() calls causing an infinite loop printing the given message endlessly (isNone_4/isNone_3).
m.v == None doesn't work either.
What's the proposed way to check against None value especially in combination with other values in the same clause.
Thanks for the help in advance! Gergely
Hi, thanks for asking this question. + and - are used for testing the existence of a field. none() is used for testing the existence of a fact (typically to filter out correlated facts). Testing for None should be done explicitly using != and ==. That said, as I tested your scenario I found a bug. I broke the JSON nil test when refactoring the 2.0.x engine. I have pushed a fix, please use version 2.0.19. The following scenario will work as expected:
with ruleset('none_test'):
@when_all(m.v == None)
def is_none(c):
print('none_test passed')
post('none_test', {'v': None})
try:
post('none_test', {'v': 'something'})
except BaseException as e:
print('none_test -> expected {0}'.format(e.message))
2.0.19 works like a charm. Thanks a lot!