Skip to content

Commit 567a3f8

Browse files
committed
Merge remote-tracking branch 'origin/dm/upgrade-simpleeval' into autostaging
2 parents 58e8e14 + c2e80a9 commit 567a3f8

File tree

7 files changed

+22
-15
lines changed

7 files changed

+22
-15
lines changed

corehq/apps/userreports/expressions/evaluator/main.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@
55
from datetime import date, datetime
66
from decimal import Decimal
77

8-
from corehq.util import eval_lazy
98
from simpleeval import (
109
DEFAULT_OPERATORS,
11-
FeatureNotAvailable,
12-
InvalidExpression,
1310
DISALLOW_FUNCTIONS,
14-
FunctionNotDefined,
1511
EvalWithCompoundTypes,
12+
FeatureNotAvailable,
13+
FunctionNotDefined,
14+
InvalidExpression,
15+
MultipleExpressions,
1616
)
1717

18-
from .functions import FUNCTIONS, CONTEXT_PARAM_NAME, NEEDS_CONTEXT_PARAM_NAME
18+
from corehq.util import eval_lazy
19+
from corehq.util.decorators import ignore_warning
20+
1921
from ...specs import EvaluationContext, FactoryContext
22+
from .functions import CONTEXT_PARAM_NAME, FUNCTIONS, NEEDS_CONTEXT_PARAM_NAME
2023

2124

2225
def safe_pow_fn(a, b):
@@ -35,6 +38,10 @@ class CommCareEval(EvalWithCompoundTypes):
3538
users less options to do crazy things that might get them / us into
3639
hard to back out of situations."""
3740

41+
def __init__(self, *args, **kw):
42+
super().__init__(*args, **kw)
43+
self.nodes.pop(ast.DictComp) # disallow dict comprehensions
44+
3845
def set_context(self, context):
3946
self._context = context.scope(self)
4047

@@ -46,7 +53,7 @@ def _eval_call(self, node):
4653
func = self.functions[node.func.id]
4754
except KeyError:
4855
raise FunctionNotDefined(node.func.id, self.expr)
49-
except AttributeError as e:
56+
except AttributeError:
5057
raise FeatureNotAvailable('Lambda Functions not implemented')
5158

5259
if func in DISALLOW_FUNCTIONS:
@@ -79,15 +86,16 @@ def eval_statements(statement, variable_context, execution_context=None):
7986

8087
evaluator = CommCareEval(operators=SAFE_OPERATORS, names=variable_context, functions=FUNCTIONS)
8188
evaluator.set_context(execution_context)
82-
return evaluator.eval(statement)
89+
with ignore_warning(MultipleExpressions):
90+
return evaluator.eval(statement)
8391

8492

8593
@dataclasses.dataclass(frozen=True)
8694
class EvalExecutionContext:
8795
evaluation_context: EvaluationContext
8896
factory_context: FactoryContext
8997
evaluator: CommCareEval = None
90-
98+
9199
@classmethod
92100
def empty(cls):
93101
return EvalExecutionContext(EvaluationContext.empty(), FactoryContext.empty())

requirements/base-requirements.in

+1-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ requests
9999
schema
100100
sentry-sdk
101101
sh
102-
# Package has an unfixed issue https://github.com/danthedeckie/simpleeval/issues/90 Can use that once https://github.com/danthedeckie/simpleeval/pull/91 is merged
103-
simpleeval @ git+https://github.com/dimagi/simpleeval.git@d85c5a9f972c0f0416a1716bb06d1a3ebc83e7ec
102+
simpleeval
104103
simplejson
105104
six
106105
socketpool

requirements/dev-requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ sh==2.0.3
604604
# -r base-requirements.in
605605
# dependency-metrics
606606
# git-build-branch
607-
simpleeval @ git+https://github.com/dimagi/simpleeval.git@d85c5a9f972c0f0416a1716bb06d1a3ebc83e7ec
607+
simpleeval==1.0.3
608608
# via -r base-requirements.in
609609
simplejson==3.17.6
610610
# via

requirements/docs-requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ sentry-sdk==2.8.0
491491
# via -r base-requirements.in
492492
sh==2.0.3
493493
# via -r base-requirements.in
494-
simpleeval @ git+https://github.com/dimagi/simpleeval.git@d85c5a9f972c0f0416a1716bb06d1a3ebc83e7ec
494+
simpleeval==1.0.3
495495
# via -r base-requirements.in
496496
simplejson==3.17.6
497497
# via

requirements/prod-requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ setproctitle==1.2.2
501501
# via -r prod-requirements.in
502502
sh==2.0.3
503503
# via -r base-requirements.in
504-
simpleeval @ git+https://github.com/dimagi/simpleeval.git@d85c5a9f972c0f0416a1716bb06d1a3ebc83e7ec
504+
simpleeval==1.0.3
505505
# via -r base-requirements.in
506506
simplejson==3.17.6
507507
# via

requirements/requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ sentry-sdk==2.8.0
461461
# via -r base-requirements.in
462462
sh==2.0.3
463463
# via -r base-requirements.in
464-
simpleeval @ git+https://github.com/dimagi/simpleeval.git@d85c5a9f972c0f0416a1716bb06d1a3ebc83e7ec
464+
simpleeval==1.0.3
465465
# via -r base-requirements.in
466466
simplejson==3.17.6
467467
# via

requirements/test-requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ sentry-sdk==2.8.0
511511
# via -r base-requirements.in
512512
sh==2.0.3
513513
# via -r base-requirements.in
514-
simpleeval @ git+https://github.com/dimagi/simpleeval.git@d85c5a9f972c0f0416a1716bb06d1a3ebc83e7ec
514+
simpleeval==1.0.3
515515
# via -r base-requirements.in
516516
simplejson==3.17.6
517517
# via

0 commit comments

Comments
 (0)