You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
d = {... any data will do ...}
f = {"$and": [{any first filter}, {}]
DataConditionEvaluator(f,d).evaluate()
Leads to stack overrun...recursive calls.
Describe what you were trying to get done.
In the automated building for filter conditions it is common to use a {} empty filter when one part of the generation does not apply vs. simply removing the filter from the $and condition itself. This way one can see that a filter was returned for that part of the and however, it was a empty filter which should pass. Thus the $and logic remains syntactically correct. For example, a user supplied filter on the left and a entitlement filter on the right. If the user is entitled to see everything then syntactically a {} may be used as a replacement.
Tell us what happened, what went wrong, and what you expected to happen.
Exception RuntimeError: maximum recursion depth exceeded
What I Did
Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.
def test_filter_stream_and2e(self):
f = {'$and': [{'blah': 0.3}, {}]}
d = {u'blah': 0.3}
DataConditionEvaluator(f, d).evaluate()
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/base.py", line 52, in c_and
for condition in body
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/base.py", line 52, in
for condition in body
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/base.py", line 27, in evaluate
return self.evaluate_logic('$and', condition)
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/evaluator.py", line 98, in evaluate_logic
return getattr(self, 'c_%s' % keyword[1:])(body)
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/base.py", line 47, in c_and
for (condition_keyword, condition_body) in body.items()
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/base.py", line 47, in
for (condition_keyword, condition_body) in body.items()
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/base.py", line 36, in evaluate_condition
for op_keyword, op_body in body.items()
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/base.py", line 36, in
for op_keyword, op_body in body.items()
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/evaluator.py", line 103, in evaluate_function
value=body,
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/evaluator.py", line 13, in wrap_method
return (field in self.data) and f(self, field, value)
RuntimeError: maximum recursion depth exceeded
The text was updated successfully, but these errors were encountered:
OK, I found the bug. If evaluate is called, with a empty condition, the line of evaluate:
condition = condition if condition else self.condition
Will incorrectly set the leaf condition (aka empty condition) back to the original condition full condition.
I don't believe this is what was desired. Instead we should be checking if the condition was explicitly None. And only set the condition to the self.condition in that case of lazy evaluate call to get the right conditiontion on entry. It was not intended to replace a {} with the original condition in the leaf since this also evaluates to False, we get the bug.
I added a handler also for the empty dict to ensure that it returns quickly.
def evaluate(self, condition=None):
# This incorrectly resets a empty dict to the full dict.
# condition = condition if condition else self.condition
# Instead
# we only want to do this when the condition was explicitly not passed in.
if condition is None: condition = self.condition
# If this is a empty condition, then we will simply return true.
if isinstance(condition, dict) and not condition: return True
return self.evaluate_logic('$and', condition)
Description
d = {... any data will do ...}
f = {"$and": [{any first filter}, {}]
DataConditionEvaluator(f,d).evaluate()
Leads to stack overrun...recursive calls.
Describe what you were trying to get done.
In the automated building for filter conditions it is common to use a {} empty filter when one part of the generation does not apply vs. simply removing the filter from the $and condition itself. This way one can see that a filter was returned for that part of the and however, it was a empty filter which should pass. Thus the $and logic remains syntactically correct. For example, a user supplied filter on the left and a entitlement filter on the right. If the user is entitled to see everything then syntactically a {} may be used as a replacement.
Tell us what happened, what went wrong, and what you expected to happen.
Exception RuntimeError: maximum recursion depth exceeded
What I Did
def test_filter_stream_and2e(self):
f = {'$and': [{'blah': 0.3}, {}]}
d = {u'blah': 0.3}
DataConditionEvaluator(f, d).evaluate()
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/base.py", line 52, in c_and
for condition in body
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/base.py", line 52, in
for condition in body
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/base.py", line 27, in evaluate
return self.evaluate_logic('$and', condition)
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/evaluator.py", line 98, in evaluate_logic
return getattr(self, 'c_%s' % keyword[1:])(body)
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/base.py", line 47, in c_and
for (condition_keyword, condition_body) in body.items()
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/base.py", line 47, in
for (condition_keyword, condition_body) in body.items()
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/base.py", line 36, in evaluate_condition
for op_keyword, op_body in body.items()
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/base.py", line 36, in
for op_keyword, op_body in body.items()
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/evaluator.py", line 103, in evaluate_function
value=body,
File "/usr/lib/python2.7/site-packages/mongo_filter_evaluator/evaluator.py", line 13, in wrap_method
return (field in self.data) and f(self, field, value)
RuntimeError: maximum recursion depth exceeded
The text was updated successfully, but these errors were encountered: