diff --git a/internal_tests/pytests/config_metplus/test_config_metplus.py b/internal_tests/pytests/config_metplus/test_config_metplus.py index 1c55fbc973..f0e669443b 100644 --- a/internal_tests/pytests/config_metplus/test_config_metplus.py +++ b/internal_tests/pytests/config_metplus/test_config_metplus.py @@ -991,4 +991,38 @@ def test_get_process_list_instances(metplus_config, input_list, expected_list): conf = metplus_config() conf.set('config', 'PROCESS_LIST', input_list) output_list = config_metplus.get_process_list(conf) - assert(output_list == expected_list) \ No newline at end of file + assert(output_list == expected_list) + +def test_getraw_sub_and_nosub(metplus_config): + raw_string = '{MODEL}_{CURRENT_FCST_NAME}' + sub_actual = 'FCST_NAME' + + config = metplus_config() + config.set('config', 'MODEL', 'FCST') + config.set('config', 'CURRENT_FCST_NAME', 'NAME') + config.set('config', 'OUTPUT_PREFIX', raw_string) + nosub_value = config.getraw('config', 'OUTPUT_PREFIX', sub_vars=False) + assert nosub_value == raw_string + + sub_value = config.getraw('config', 'OUTPUT_PREFIX', sub_vars=True) + assert sub_value == sub_actual + +def test_getraw_instance_with_unset_var(metplus_config): + """! Replicates bug where CURRENT_FCST_NAME is substituted with + an empty string when copied from an instance section + """ + pytest.skip() + instance = 'my_section' + config = metplus_config() + config.set('config', 'MODEL', 'FCST') + + config.add_section(instance) + config.set('config', 'CURRENT_FCST_NAME', '') + config.set(instance, 'OUTPUT_PREFIX', '{MODEL}_{CURRENT_FCST_NAME}') + new_config = ( + config_metplus.replace_config_from_section(config, + instance, + required=False) + ) + new_config.set('config', 'CURRENT_FCST_NAME', 'NAME') + assert new_config.getraw('config', 'OUTPUT_PREFIX') == 'FCST_NAME' diff --git a/metplus/util/config_metplus.py b/metplus/util/config_metplus.py index 353eed0d31..3ce629bdc2 100644 --- a/metplus/util/config_metplus.py +++ b/metplus/util/config_metplus.py @@ -458,14 +458,14 @@ def replace_config_from_section(config, section, required=True): for key in all_configs: new_config.set(section_to_copy, key, - config.getraw(section_to_copy, key)) + config.getraw(section_to_copy, key, sub_vars=False)) # override values in [config] with values from {section} all_configs = config.keys(section) for key in all_configs: new_config.set('config', key, - config.getraw(section, key)) + config.getraw(section, key, sub_vars=False)) return new_config @@ -585,7 +585,7 @@ def remove_current_vars(self): self._conf.remove_option('config', current_var) # override get methods to perform additional error checking - def getraw(self, sec, opt, default='', count=0): + def getraw(self, sec, opt, default='', count=0, sub_vars=True): """ parse parameter and replace any existing parameters referenced with the value (looking in same section, then config, dir, and os environment) @@ -614,6 +614,10 @@ def getraw(self, sec, opt, default='', count=0): self.check_default(sec, opt, default) return default + # if not substituting values of other variables return value + if not sub_vars: + return in_template + # get inner-most tags that could potentially be other variables match_list = re.findall(r'\{([^}{]*)\}', in_template) for var_name in match_list: @@ -1320,14 +1324,6 @@ def check_for_deprecated_met_config(config): sed_cmds = [] all_good = True - # set CURRENT_* METplus variables in case they are referenced in a - # METplus config variable and not already set - for fcst_or_obs in ['FCST', 'OBS']: - for name_or_level in ['NAME', 'LEVEL']: - current_var = f'CURRENT_{fcst_or_obs}_{name_or_level}' - if not config.has_option('config', current_var): - config.set('config', current_var, '') - # check if *_CONFIG_FILE if set in the METplus config file and check for # deprecated environment variables in those files met_config_keys = [key for key in config.keys('config')