Fix: allow __ prefixed temp variables in recipe validation#1111
Merged
jkasturi-sf merged 1 commit intomainfrom Jan 9, 2026
Merged
Fix: allow __ prefixed temp variables in recipe validation#1111jkasturi-sf merged 1 commit intomainfrom
jkasturi-sf merged 1 commit intomainfrom
Conversation
- Override is_safe_attribute in SandboxedNativeEnvironment to allow __ prefixed attributes on MockObjectRow objects - Fix MockObjectRow.__getattr__ to allow valid __ prefixed fields - Add error rollback for cross-context field resolution failures - Add comprehensive test suite for __ prefixed temp variable handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Allow
__Prefixed Temp Variables in Recipe ValidationProblem
The recipe validation logic was incorrectly flagging temporary variables (those prefixed with
__) as errors. Users would see validation errors like:This blocked valid recipes that use
__prefixed variables as temporary/hidden fields from passing validation.Root Causes
Three separate issues were identified through systematic debugging:
1.
MockObjectRow.__getattr__rejecting all underscore attributesLocation:
recipe_validator.pyMockObjectRow.__getattr__The check
if attr.startswith("_"):rejected ALL attributes starting with underscore, including valid__prefixed temp variable fields that were properly defined in the object.2. Jinja2 SandboxedEnvironment blocking
__attribute accessLocation:
recipe_validator.pySandboxedNativeEnvironmentclassJinja2's sandbox security blocks access to any attribute starting with underscore for security reasons. This is appropriate for preventing access to Python internals like
__class__, but incorrectly blocked legitimate Snowfakery temp variables.3. Errors propagating from context-mismatched field resolution
Location:
recipe_validator.pyMockObjectRow.__getattr__field resolutionWhen resolving field values from a different object context (e.g., accessing
tech_user.__gender_folderfrom within aServiceResourceobject), errors would propagate instead of gracefully falling back to mock values.Solution
Fix 1: Allow valid
__prefixed fields in MockObjectRowFix 2: Override
is_safe_attributein SandboxedNativeEnvironmentFix 3: Add error rollback for cross-context field resolution
When resolving field values fails due to context mismatch, remove the spurious errors and fall back to mock values instead of reporting false validation errors.
Testing
Added
TestDoubleUnderscoreTempVariablestest class with 9 comprehensive tests:test_dunder_variable_within_same_object__prefixed variable usagetest_dunder_variable_cross_object_referenceobj.__fieldsyntaxtest_multiple_dunder_variables__vars working togethertest_dunder_variable_in_nested_friendstest_dunder_variable_with_integer_operationstest_dunder_variable_conditional_logictest_dunder_variable_not_accessible_before_definitiontest_dunder_variable_in_random_choice_contextrandom_choicepatterntest_dunder_variable_complex_nested_scenarioAll 113 tests in
test_recipe_validator.pypass.Example Recipe That Now Validates
Backward Compatibility
This change is fully backward compatible. It only allows previously-rejected valid recipes to pass validation. No existing valid recipes are affected.