From 7c1c8b2ac90aa0f78a593b8eb043ef10012e9907 Mon Sep 17 00:00:00 2001 From: Robert Porsch Date: Tue, 22 Jun 2021 17:29:36 +0800 Subject: [PATCH] Custom Reset Request does not support lists in Given we have the following request body: ```json { "instances": [ { text: "{{ text }}" } ] } ``` The following method is unable to replace "{{ text }}" with the appropriate text. ```python def find_and_replace_value(obj, value, target='{{ text }}'): for k, v in obj.items(): if v == target: obj[k] = value return if isinstance(v, dict): find_and_replace_value(v, value, target) ``` The proposed changes would address this issue. --- auto_labeling_pipeline/models.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/auto_labeling_pipeline/models.py b/auto_labeling_pipeline/models.py index bb06f99..7c00cec 100644 --- a/auto_labeling_pipeline/models.py +++ b/auto_labeling_pipeline/models.py @@ -39,12 +39,16 @@ def get_all_subclasses(cls): def find_and_replace_value(obj, value, target='{{ text }}'): - for k, v in obj.items(): - if v == target: - obj[k] = value - return - if isinstance(v, dict): - find_and_replace_value(v, value, target) + if isinstance(obj, dict): + for k, v in obj.items(): + if v == target: + obj[k] = value + return + if isinstance(v, (dict, list)): + find_and_replace_value(v, value, target) + if isinstance(obj, list): + for item in obj: + find_and_replace_value(item, value, target) class CustomRESTRequestModel(RequestModel):