fix(loader): preserve non-env {{...}} placeholders in ConfigLoader (#81)#132
Open
owen-pengtao wants to merge 1 commit into
Open
Conversation
…ontextforge-org#81) ConfigLoader.load_config renders the whole plugin config.yaml through a single jinja pass with the default (empty) Undefined, so any {{...}} that is not an env reference is silently blanked to "". A plugin that stores a runtime template in its config (e.g. WebhookNotification's default_template) is therefore emptied at load time and later emits an all-empty, invalid body. Render with jinja2.DebugUndefined so undefined names (everything except the env.* values passed to render()) survive verbatim as {{ name }} instead of being blanked, while env.* references are still substituted. Adds regression tests covering env substitution, non-env placeholder preservation, and use_jinja=False. Fixes contextforge-org#81. Signed-off-by: Owen Peng <tao.peng@tibco.com>
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.
Summary
Fixes #81 —
ConfigLoader.load_configblanks non-env{{...}}placeholders in the plugin config.load_configrenders the entireconfig.yamlthrough one jinja pass with the default (empty)Undefined:Because the render only defines
env, any{{...}}that is not anenvreference is silently rendered to""at load time — including placeholders a plugin legitimately stores in its config to render itself later, at runtime. The reported symptom:WebhookNotification'sdefault_templateis blanked to
{ "event": "", "timestamp": "", "violation": , ... }at load, so the plugin posts an all-empty, invalid-JSON body.Fix
Render with
jinja2.DebugUndefined(issue #81's suggested option 1) so undefined names — everything except theenv.*values passed torender()— survive verbatim as{{ name }}instead of being blanked, whileenv.*references are still substituted.Behavior note
A bare
{{ env.MISSING }}for an unset env var now renders literally as{{ env.MISSING }}instead of"". Configs that want an empty fallback should use thedefaultfilter ({{ env.X | default('') }}), which continues to work. This is the documented trade-off of the DebugUndefined approach.Tests
Adds
tests/unit/cpex/framework/loader/test_config_loader.py:env.*reference is still substituted;env{{...}}runtime template placeholder is preserved (the [BUG]: ConfigLoader.load_config Jinja pass blanks non-env {{...}} placeholders in plugin config #81 regression);use_jinja=Falseleaves everything literal.Verified against the real
0.1.xConfigLoader: current behavior blanks the placeholders; with this change the three tests pass and the WebhookNotification-styledefault_templatesurvives load.Signed-off-by: Owen Peng tao.peng@tibco.com