fix(util): avoid passing None to load_yaml on failed jinja render - #7032
Open
sundeep8967 wants to merge 1 commit into
Open
fix(util): avoid passing None to load_yaml on failed jinja render#7032sundeep8967 wants to merge 1 commit into
sundeep8967 wants to merge 1 commit into
Conversation
When render_jinja_payload_from_file returns None (e.g. due to an undefined attribute error), read_conf previously assigned config_file to None, causing load_yaml to crash with an AttributeError. Only update config_file when a valid rendered payload is returned. Fixes canonicalGH-7007
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.
Problem
When a templated YAML config cannot be rendered (for example, when referencing a missing nested attribute like
{{ ds.meta_data.placement.region }}on a platform where it is not defined),render_jinja_payload_from_file()logs a warning and returnsNone.In
util.read_conf(),config_filewas being unconditionally overwritten with thisNonereturn value:Subsequently,
load_yaml(config_file)was called withconfig_file=None, resulting indecode_binary(None)raising:and causing the
init-local/initboot stage to fail.Solution
util.read_conf(), capture the result ofrender_jinja_payload_from_file()in a temporary variable and only updateconfig_fileif the rendered output is notNone.test_read_conf_with_failed_jinja_render_undefined_attributeintests/unittests/test_util.pyasserting that when jinja rendering fails due to an undefined attribute, the original configuration is preserved and loaded without raising anAttributeError.Fixes #7007
Testing
AttributeErrorondecode_binary(None)reproduced).pytest tests/unittests/test_util.py— all 318 tests passed.