Skip to content

fix(mappers): Support simpleeval 1.0.5+ by subclassing simpleeval.EvalWithCompoundTypes#3601

Merged
edgarrmondragon merged 1 commit into
v0.53from
simpleeval-vuln
Apr 15, 2026
Merged

fix(mappers): Support simpleeval 1.0.5+ by subclassing simpleeval.EvalWithCompoundTypes#3601
edgarrmondragon merged 1 commit into
v0.53from
simpleeval-vuln

Conversation

@edgarrmondragon
Copy link
Copy Markdown
Collaborator

@edgarrmondragon edgarrmondragon commented Apr 15, 2026

Related

Summary 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:

  • Introduce a dedicated mapper expression evaluator subclass to control how AST nodes, names, and disallowed items are handled during evaluation.

Bug Fixes:

  • Fix incompatibility with simpleeval 1.0.5+ by bypassing its new redundant container safety scan in a controlled way.

Enhancements:

  • Wrap datetime and json modules with simpleeval.ModuleWrapper when exposing them as mapper functions to align with simpleeval’s safety model.

Build:

  • Pin simpleeval to version 1.0.7 in project dependencies.

…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>
@edgarrmondragon edgarrmondragon requested a review from a team as a code owner April 15, 2026 21:26
@edgarrmondragon edgarrmondragon self-assigned this Apr 15, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Apr 15, 2026

Reviewer's Guide

Adds 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 _MapperEval

sequenceDiagram
    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
Loading

Class diagram for _MapperEval and CustomStreamMap evaluator integration

classDiagram
    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
Loading

File-Level Changes

Change Details Files
Introduce a custom evaluator subclass to control simpleeval behavior for mapper expressions and name resolution.
  • Add version-gated import for typing.override (typing vs typing_extensions).
  • Define _MapperEval subclass of simpleeval.EvalWithCompoundTypes that no-ops _check_disallowed_items to bypass the new container scan introduced in simpleeval 1.0.5 while documenting safety assumptions.
  • Override _eval to provide a local node-dispatch implementation that raises FeatureNotAvailable for unsupported AST node types.
  • Override _eval_name to mirror upstream logic while explicitly running _check_disallowed_items on values from names/functions, preserving simpleeval’s disallowed item checks where intentional.
singer_sdk/mapper.py
Wire the new evaluator into existing mapper paths and harden function definitions to be safe under simpleeval 1.0.5+ security changes.
  • Replace direct uses of simpleeval.EvalWithCompoundTypes in CustomStreamMap.init and _eval_stream with the new _MapperEval class while keeping type hints compatible.
  • Wrap datetime and json in simpleeval.ModuleWrapper before exposing them in the evaluator functions dict to satisfy simpleeval’s module safety expectations.
singer_sdk/mapper.py
Update dependency constraints to a known-good simpleeval release that includes the upstream fix this PR reimplements locally.
  • Change simpleeval dependency specifier from a version range excluding 1.0.5 to an exact pin at simpleeval==1.0.7.
  • Refresh uv.lock to reflect the new simpleeval version and its dependency resolution.
pyproject.toml
uv.lock

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@edgarrmondragon edgarrmondragon changed the title fix(mappers): Support simpleeval 1.0.5+ by subclassing simpleeval.EvalWithCompoundTypes (#3595) fix(mappers): Support simpleeval 1.0.5+ by subclassing simpleeval.EvalWithCompoundTypes Apr 15, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.13%. Comparing base (bae8c09) to head (29780d5).
⚠️ Report is 1 commits behind head on v0.53.

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           
Flag Coverage Δ
core 81.98% <ø> (ø)
end-to-end 76.37% <ø> (ø)
optional-components 43.48% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 15, 2026

Merging this PR will not alter performance

✅ 8 untouched benchmarks


Comparing simpleeval-vuln (29780d5) with v0.53 (bae8c09)

Open in CodSpeed

@edgarrmondragon edgarrmondragon merged commit 6608ae1 into v0.53 Apr 15, 2026
43 of 44 checks passed
@edgarrmondragon edgarrmondragon deleted the simpleeval-vuln branch April 15, 2026 21:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant