Commit cd440508 authored by Matias Guijarro's avatar Matias Guijarro
Browse files

fix issue 2118: to_dict() not dereferencing references in list in dict

parent 58b9b6e7
Pipeline #34484 failed with stages
in 105 minutes and 57 seconds
......@@ -103,7 +103,9 @@ def get_config(base_path="", timeout=3., raise_yaml_exc=True):
class ConfigReference:
@staticmethod
def is_reference(name):
return name.startswith("$")
if isinstance(name, str):
return name.startswith("$")
return False
def __init__(self, parent, value):
self._parent = parent
......@@ -523,6 +525,13 @@ class ConfigNode(MutableMapping):
for k, v in d.items():
if isinstance(v, str) and ConfigReference.is_reference(v):
d[k] = ConfigReference(self.parent, v).dereference()
elif isinstance(v, list):
d[k] = [
ConfigReference(self.parent, item).dereference()
if ConfigReference.is_reference(item)
else item
for item in v
]
return d
return json.JSONDecoder(object_hook=decoder_hook).decode(
......
......@@ -164,6 +164,20 @@ def test_references(beacon, object_name, get_func_name, copy):
s1vo.__close__()
def test_issue_2118(beacon):
cfg = beacon.get("fscan_eh3")
s1hg = beacon.get("s1hg")
s1vo = beacon.get("s1vo")
cfg = cfg.to_dict()
try:
assert cfg["devices"]["musst"][0] is s1hg
assert cfg["devices"]["musst"][1] is s1vo
finally:
s1hg.__close__()
s1vo.__close__()
def test_issue_451_infinite_recursion(beacon):
refs_cfg = beacon.get_config("refs_test")
......
......@@ -17,5 +17,9 @@
position: 1
scan:
axis: $m0
- name: fscan_eh3
devices:
musst: [ $s1hg, $s1vo ]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment