Skip to content

Commit

Permalink
fix: escaping cases for component not being acquired by ID
Browse files Browse the repository at this point in the history
  • Loading branch information
mmikita95 committed Feb 20, 2024
1 parent 42d2439 commit 50f465c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/streamsync/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,20 +769,25 @@ def replacer(matched):

component_id = instance_path[-1]["componentId"]
component = self.ct.get_component(component_id)
field_value = component.content.get(field_key) or default_field_value
replaced = self.template_regex.sub(replacer, field_value)
if component:
field_value = component.content.get(field_key) or default_field_value
replaced = self.template_regex.sub(replacer, field_value)

if as_json:
return json.loads(replaced)
if as_json:
return json.loads(replaced)
else:
return replaced
else:
return replaced
raise ValueError(f"Couldn't acquire a component by ID '{component_id}'")

def get_context_data(self, instance_path: InstancePath) -> Dict[str, Any]:
context: Dict[str, Any] = {}
for i in range(len(instance_path)):
path_item = instance_path[i]
component_id = path_item["componentId"]
component = self.ct.get_component(component_id)
if not component:
continue
if component.type != "repeater":
continue
if i + 1 >= len(instance_path):
Expand Down

0 comments on commit 50f465c

Please sign in to comment.