fix(mappers): Support simpleeval 1.0.5+ by subclassing simpleeval.EvalWithCompoundTypes#3601
Conversation
…EvalWithCompoundTypes` (#3595) ## Related - Closes #3561 - Re-implements upstream danthedeckie/simpleeval#181 ## Summary by Sourcery Support newer simpleeval versions in mapper expression evaluation while preserving safety guarantees for stream map expressions. Bug Fixes: - Restore compatibility with simpleeval 1.0.5+ by customizing evaluation to bypass redundant disallowed-item checks that conflict with mapper usage. Enhancements: - Introduce a dedicated _MapperEval subclass to centralize mapper-specific simpleeval behavior and safety constraints. - Wrap datetime and json modules with simpleeval.ModuleWrapper when exposing them as mapper functions to align with simpleeval's security model. Build: - Relax the simpleeval dependency to require version 1.0.5 or later in project configuration. ## Summary by Sourcery Restore compatibility of mapper expression evaluation with newer simpleeval versions while maintaining existing safety guarantees. Bug Fixes: - Fix incompatibility with simpleeval 1.0.5+ by using a custom evaluator that bypasses redundant disallowed-item checks conflicting with mapper use cases. Enhancements: - Introduce a dedicated _MapperEval subclass to centralize mapper-specific simpleeval behavior and security constraints. - Wrap the datetime and json modules with simpleeval.ModuleWrapper when exposing them as mapper functions to align with simpleeval's security model. Build: - Update the simpleeval dependency constraint to pin to version 1.0.7. --------- Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
Reviewer's GuideAdds a custom _MapperEval subclass of simpleeval.EvalWithCompoundTypes to restore pre-1.0.5 evaluation behavior while remaining compatible with simpleeval>=1.0.5 and tightening safety by wrapping module functions, and wires this evaluator into mapper usage while pinning simpleeval to 1.0.7. Sequence diagram for expression evaluation with _MapperEvalsequenceDiagram
participant Caller
participant CustomStreamMap
participant _MapperEval
participant simpleeval_ModuleWrapper
Caller->>CustomStreamMap: transform(record)
CustomStreamMap->>CustomStreamMap: functions() builds dict
CustomStreamMap->>simpleeval_ModuleWrapper: wrap(datetime)
CustomStreamMap->>simpleeval_ModuleWrapper: wrap(json)
CustomStreamMap->>_MapperEval: init(functions=functions)
CustomStreamMap->>_MapperEval: _eval(expr, record, context)
activate _MapperEval
_MapperEval->>_MapperEval: _eval(ast_node)
_MapperEval->>_MapperEval: _eval_name(ast_name)
_MapperEval->>_MapperEval: _check_disallowed_items(item)
_MapperEval-->>CustomStreamMap: result
deactivate _MapperEval
CustomStreamMap-->>Caller: transformed_record
Class diagram for _MapperEval and CustomStreamMap evaluator integrationclassDiagram
class simpleeval_EvalWithCompoundTypes {
<<external>>
+eval(expr)
+_eval(node)
+_eval_name(node)
+_check_disallowed_items(item)
}
class _MapperEval {
+_check_disallowed_items(item)
+_eval(node)
+_eval_name(node)
}
class CustomStreamMap {
-functions: dict~str, Callable~
-expr_evaluator: simpleeval_EvalWithCompoundTypes
+functions() dict~str, Callable~
+transform(record) dict | None
+_eval(expr, record, context) Any
}
simpleeval_EvalWithCompoundTypes <|-- _MapperEval
CustomStreamMap ..> _MapperEval : uses as expr_evaluator
class simpleeval_ModuleWrapper {
<<external>>
}
class datetime_module {
<<module>>
}
class json_module {
<<module>>
}
CustomStreamMap ..> simpleeval_ModuleWrapper : wraps datetime, json
CustomStreamMap ..> datetime_module
CustomStreamMap ..> json_module
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
simpleeval 1.0.5+ by subclassing simpleeval.EvalWithCompoundTypes (#3595)simpleeval 1.0.5+ by subclassing simpleeval.EvalWithCompoundTypes
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v0.53 #3601 +/- ##
=======================================
Coverage 94.13% 94.13%
=======================================
Files 69 69
Lines 5783 5783
Branches 716 716
=======================================
Hits 5444 5444
Misses 236 236
Partials 103 103
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Documentation build overview
48 files changed ·
|
Related
simpleeval1.0.5+ by implementingModuleWrapperfor modules exposed to stream maps expressions #3561simpleeval1.0.5+ by subclassingsimpleeval.EvalWithCompoundTypes#3595Summary by Sourcery
Update stream mapper expression evaluation to be compatible with simpleeval 1.0.5+ while preserving the mapper’s existing safety guarantees.
New Features:
Bug Fixes:
Enhancements:
Build: