Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value type for Senses from string to JSON #1466

Open
vanlummelhuizen opened this issue Jan 23, 2025 · 3 comments
Open

Value type for Senses from string to JSON #1466

vanlummelhuizen opened this issue Jan 23, 2025 · 3 comments

Comments

@vanlummelhuizen
Copy link
Collaborator

vanlummelhuizen commented Jan 23, 2025

For API endpoint /dictionary/api_update_gloss/<dataset>/<gloss>, change the value type for the Senses key in the JSON payload from string to JSON object.

See also #1360

@susanodd

This comment has been minimized.

@susanodd
Copy link
Collaborator

susanodd commented Feb 3, 2025

@vanlummelhuizen solution:

Below is the diff to get my API call using cURL to work.

diff --git a/signbank/gloss_update.py b/signbank/gloss_update.py
index 023c1592..675de932 100755
--- a/signbank/gloss_update.py
+++ b/signbank/gloss_update.py
@@ -116,7 +116,7 @@ def get_gloss_update_human_readable_value_dict(request):
     value_dict = dict()
     for field in post_data.keys():
         value = post_data.get(field, '')
-        value_dict[field] = value.strip()
+        value_dict[field] = value.strip() if isinstance(value, str) else value
     return value_dict
 
 
@@ -126,7 +126,7 @@ def check_fields_can_be_updated(value_dict, dataset, language_code):
     for field in value_dict.keys():
         if field not in api_fields_2024 and field not in language_fields:
             errors[field] = _("Field update not available")
-        if field == "Senses":
+        if field == "Senses" and isinstance(value_dict[field], str):
             new_senses, formatting_error_senses = convert_string_to_dict_of_list_of_lists(value_dict[field])
             if formatting_error_senses:
                 errors[field] = formatting_error_senses
@@ -553,10 +553,12 @@ def gloss_update(gloss, update_fields_dict, language_code):
             continue
         if human_readable_field == 'Senses':
             original_value = get_original_senses_value(gloss)
-            new_senses, errors = convert_string_to_dict_of_list_of_lists(new_field_value)
-            if errors:
-                # already checked at a previous step
-                continue
+            new_senses = new_field_value
+            if isinstance(new_senses, str):
+                new_senses, errors = convert_string_to_dict_of_list_of_lists(new_field_value)
+                if errors:
+                    # already checked at a previous step
+                    continue
             if original_value != new_senses:
                 fields_to_update[human_readable_field] = (original_value, new_senses)
             continue

susanodd pushed a commit that referenced this issue Feb 6, 2025
Repaired as per review, actually other issue.
@susanodd
Copy link
Collaborator

susanodd commented Feb 7, 2025

This has been deployed and it works.

I added a comment to Swagger to instruct users to use DOUBLE QUOTES.

(Otherwise it does not work. I gives a weird error of 500. Swagger adds extra backwards quotes around stuff inside the json dict for senses.... So use double quotes!!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants