Preserve saved globals when copying DelayEvaluator - #3346
Conversation
Attribute and item access copy the evaluator and previously dropped caller globals, so config_expr with custom functions failed after chaining.
Greptile SummaryThe PR preserves caller globals by reference when copying or deep-copying a
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the previously requested chained result-level evaluation is now covered and would fail under the original globals-dropping behavior.
|
| Filename | Overview |
|---|---|
| metaflow/user_configs/config_parameters.py | Copy and deep-copy operations now retain the saved globals reference while preserving the existing access-copy behavior. |
| test/unit/test_delay_evaluator.py | Adds focused regression coverage, including a chained call that reaches evaluation and asserts the resolved result. |
Reviews (2): Last reviewed commit: "Cover chained DelayEvaluator evaluation ..." | Re-trigger Greptile
Shriprasad-P
left a comment
There was a problem hiding this comment.
I independently reproduced the namespace-loss issue and verified that the implementation fixes it.
Preserving saved_globals by reference in both __copy__ and __deepcopy__ matches the existing DelayEvaluator semantics. Chained attribute/item evaluation that fails with a NameError on the base revision succeeds on this PR, while the copied access state remains independent.
One non-blocking coverage gap remains: the new tests verify _globals / _access directly but never call the copied or chained DelayEvaluator. Adding one regression test that evaluates the chained expression and asserts its returned value would cover the actual user-visible failure path rather than only the internal state.
Small comment nit as well: the new __copy__ comment uses config_expr("my_func()") as the example for attribute/item access, but non-identifier expressions have _access=None and don't take that chaining path. An identifier-based example such as config_expr("my_func").project would describe the affected path more accurately.
The implementation itself looks correct.
|
@Shriprasad-P yeah fair those tests were only poking at _globals. added one that actually calls the chained evaluator and checks the return value. also swapped the comment to config_expr("my_func").project, my_func() was the wrong example there |
|
Thanks for preparing the implementation. I originally reported this issue with the same fix and had a local patch and tests ready, but I was waiting for maintainer acknowledgement as required by the contribution guidelines. I am happy to help review or test this change if useful. |
|
@SahilKumar75 ah i didnt know you already had a patch sitting around. this was just copy dropping saved_globals. if you wanna poke at the tests go for it. |
PR Type
[x] Bug fix
[ ] New feature
[ ] Core Runtime change (higher bar; see CONTRIBUTING.md)
[ ] Docs / tooling
[ ] Refactoring
Summary
Attribute and item access on DelayEvaluator copy the object and previously dropped the caller globals captured by config_expr. Custom functions then raised NameError after any chained access.
Issue
Fixes #3345
Reproduction
Runtime: local
Commands to run:
Where evidence shows up: unit test output
Before (error / log snippet)
After (evidence that fix works)
Root Cause
copy and deepcopy constructed DelayEvaluator(self._config_expr) without saved_globals. getattr and getitem call copy, so chaining dropped the globals config_expr had stored.
Why This Fix Is Correct
Pass saved_globals=self._globals into both copy paths so the reference is kept, matching the previous comment that globals stay as a reference. Scope is limited to those two methods plus unit tests.
Failure Modes Considered
Tests
[x] Unit tests added/updated
[ ] Reproduction script provided (required for Core Runtime)
[ ] CI passes
[ ] If tests are impractical: explain why below and provide manual evidence above
Non Goals
No change to eval semantics beyond preserving the globals reference across copy.
AI Tool Usage
[x] No AI tools were used in this contribution
[ ] AI tools were used (describe below)