adobe / himl

A hierarchical yaml config in Python

Home Page:https://pypi.org/project/himl/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`ConfigProcessor.process(skip_interpolations=True)` flag not working as expected

cunningr opened this issue · comments

Expected Behaviour

When enabling the flag skip_interpolations=True for ConfigProcessor we would expect strings that would otherwise be interpolated to be left in tact.

Actual Behaviour

Value strings with "{{ some.param.value }}" are replaced with the referenced values.

Reproduce Scenario (including but not limited to)

Parse a hierarchical config with "{{ some.param.value }}" and the flag skip_interpolations=True set. Something like;

config = config_processor.process(
    path=path,
    filters=filters,
    exclude_keys=exclude_keys,
    output_format=output_format,
    print_data=True,
    skip_interpolations=True
)

Steps to Reproduce

See above. On inspection of the class method ConfigProcessor.process() we notice that a call to generator.resolve_interpolations() is outside of the if not skip_interpolations: test;

https://github.com/adobe/himl/blob/master/himl/config_generator.py#L73

However, commenting out this line still doesn't seem to prevent these params being interpolated. Adding a debug print() statement here and returning immediately afterwards (in an effort to disable interpolation completely) shows that this interpolation func is still being called but will prevent the the strings from being processed.

Platform and Version

Darwin 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:46:32 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T6000 arm64
Python 3.8.9
attrs==21.4.0
backports.functools-lru-cache==1.6.4
boto3==1.21.1
botocore==1.24.46
certifi==2022.5.18.1
charset-normalizer==2.0.12
deepdiff==5.8.1
deepmerge==1.0.1
himl==0.9.0
hvac==0.11.2
idna==3.3
importlib-resources==5.7.1
jmespath==0.10.0
jsonschema==4.5.1
lru-cache==0.2.3
ordered-set==4.1.0
pathlib2==2.3.7.post1
pyrsistent==0.18.1
python-dateutil==2.8.2
PyYAML==6.0
requests==2.27.1
s3transfer==0.5.2
six==1.16.0
urllib3==1.26.9
zipp==3.8.0

Sample Code that illustrates the problem

networks:
    o3:
      name: "some_name"
      ipv4:
        subnet_name: "some_other_name"

network:
    name: "{{ networks.o3.name }}"
    shared: false
    subnet:
      name: "{{ networks.o3.ipv4.subnet_name }}"

Logs taken while reproducing problem

With the current code base:

  network:
    name: some_name
    shared: false
    subnet:
      name: some_other_name

When interpolation is completely disabled in code:

  network:
    name: '{{networks.o3.name}}'
    shared: false
    subnet:
      name: '{{networks.o3.ipv4.subnet_name}}'

thanks for reporting this @cunningr
Would you try to file a PR please to fix this behaviour?
thanks in advance