fix(actions): handle empty string values in create_event (#1700)#1934
fix(actions): handle empty string values in create_event (#1700)#1934LeSingh1 wants to merge 2 commits into
Conversation
…#1700) `create_event` checks `v[0] == "$"` after confirming `v` is a string to detect `$variable` references in the context. For an empty string this raises `IndexError: string index out of range` because there is no `v[0]`. Switch to `v.startswith("$")`, which returns False for the empty string and matches the pattern used elsewhere in the codebase for the same check. Add two unit tests in `tests/test_actions.py`: one for the empty-string case (which raises on the old code) and one confirming the existing `$user_name` resolution path still works. Signed-off-by: Shaurya Singh <sshaurya914@gmail.com>
Greptile SummaryThis PR fixes a one-line bug in
|
| Filename | Overview |
|---|---|
| nemoguardrails/actions/core.py | Single-line fix: v[0] == "$" → v.startswith("$") eliminates IndexError on empty strings; logic is correct and minimal. |
| tests/test_actions.py | Adds two well-scoped regression tests covering the empty-string bug and the $variable resolution path; assertions align with new_event_dict output shape. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[create_event called] --> B[Build event_dict via new_event_dict]
B --> C[Iterate over event_dict items]
C --> D{Is value a string?}
D -- No --> E[Keep value unchanged]
D -- Yes --> F{"v.startswith('$')?"}
F -- "No (includes empty string)" --> E
F -- Yes --> G{context provided?}
G -- Yes --> H[Resolve from context]
G -- No --> I[Set to None]
H --> J[Return ActionResult]
I --> J
E --> J
Reviews (2): Last reviewed commit: "style(tests): apply ruff format to test_..." | Re-trigger Greptile
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR fixes a bug in Changescreate_event robustness
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Signed-off-by: Shaurya Singh <sshaurya914@gmail.com>
Fixes #1700.
create_eventinnemoguardrails/actions/core.pychecksv[0] == "$"after confirmingvis a string, to detect$variablereferences that should be looked up in the action context. Whenvis the empty string"", this raisesIndexError: string index out of rangebecause there is nov[0].The fix replaces
v[0] == "$"withv.startswith("$"), which returns False for the empty string and matches the pattern used elsewhere in the codebase. The behavior for non-empty strings is unchanged.Reproduction from the issue:
Tests
Added two unit tests in
tests/test_actions.py:test_create_event_accepts_empty_string_values— fails on the old code, passes after the fixtest_create_event_still_resolves_dollar_prefixed_references— confirms$user_namelookup againstcontextstill worksSummary by CodeRabbit
Bug Fixes
Tests