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 · 2 comments
Open

Value type for Senses from string to JSON #1466

vanlummelhuizen opened this issue Jan 23, 2025 · 2 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
Copy link
Collaborator

susanodd commented Jan 29, 2025

This is only needed because somebody incorrectly rewrote the type when they wrote the Swagger code.

The update API command is multilingual, according to the LANGUAGE_CODE. Moreover, the domain of the senses depends on what languages are in the dataset.

Swagger has become hard-coded.

@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

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

No branches or pull requests

2 participants