Refactor Vertex class to handle code parsing and string unescaping
This commit is contained in:
parent
33a82cad06
commit
aca19ef54f
1 changed files with 6 additions and 3 deletions
|
|
@ -244,7 +244,7 @@ class Vertex:
|
||||||
for key, value in self.data["node"]["template"].items()
|
for key, value in self.data["node"]["template"].items()
|
||||||
if isinstance(value, dict)
|
if isinstance(value, dict)
|
||||||
}
|
}
|
||||||
params = self.params.copy() if self.params else {}
|
params = {}
|
||||||
|
|
||||||
for edge in self.edges:
|
for edge in self.edges:
|
||||||
if not hasattr(edge, "target_param"):
|
if not hasattr(edge, "target_param"):
|
||||||
|
|
@ -287,8 +287,7 @@ class Vertex:
|
||||||
if value.get("type") == "code":
|
if value.get("type") == "code":
|
||||||
try:
|
try:
|
||||||
params[key] = ast.literal_eval(val) if val else None
|
params[key] = ast.literal_eval(val) if val else None
|
||||||
except Exception as exc:
|
except Exception:
|
||||||
logger.debug(f"Error parsing code: {exc}")
|
|
||||||
params[key] = val
|
params[key] = val
|
||||||
elif value.get("type") in ["dict", "NestedDict"]:
|
elif value.get("type") in ["dict", "NestedDict"]:
|
||||||
# When dict comes from the frontend it comes as a
|
# When dict comes from the frontend it comes as a
|
||||||
|
|
@ -312,6 +311,10 @@ class Vertex:
|
||||||
params[key] = float(val)
|
params[key] = float(val)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
params[key] = val
|
params[key] = val
|
||||||
|
elif value.get("type") == "str" and val is not None:
|
||||||
|
# val may contain escaped \n, \t, etc.
|
||||||
|
# so we need to unescape it
|
||||||
|
params[key] = val.encode().decode("unicode_escape")
|
||||||
elif val is not None and val != "":
|
elif val is not None and val != "":
|
||||||
params[key] = val
|
params[key] = val
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue