Repository: WordPress/openverse-api

Issue:
Remove `required` attribute from unidirectional serializers
## Problem
<!-- Describe a problem solved by this feature; or delete the section entirely. -->
Most serializers in the API are unidirectional, in that they serialize instances to JSON but not vice versa. These serializers have no use for the [`required` attribute](https://www.django-rest-framework.org/api-guide/fields/#required).

## Solution
The `required` argument should be removed from all output serializers.

## Additional context
<!-- Add any other context about the feature here; or delete the section entirely. -->
To be fair, the `required` prop has a notable effect during serialization. If set to `False` fields with the value `null` are omitted entirely, which is counterintuitive and may be surprising, so we better leave it to the default value of `True`.

## Implementation
<!-- Replace the [ ] with [x] to check the box. -->
- [ ] 🙋 I would be interested in implementing this feature.



Discussion:
Hi @dhruvkb,
This issue seems to be a good initiation of my journey toward contribution to FOSS projects.
Can you please assign this to me?
Welcome, @sahil-R! I assigned the issue to you. Thank you for your interest in improving Openverse.
@krysal @dhruvkb  hey, I have cloned the repo and trying to build the server but pipenv isn't working and for some reason the curl as well for registration, I have edited the code but want to test it, the slack channel is also not working can I please get some heads help

@krysal @dhruvkb i managed to run the django server anyways,Thank you.
Hi @sahil-R, to build the server you do not need Pipenv. You can use the Docker-based development setup. Follow the steps in our [Quickstart guide](https://wordpress.github.io/openverse-api/guides/quickstart.html) and comment here if you face any issues.

> the slack channel is also not working

Can you elaborate on this? To the best of my knowledge the Slack channel is very active. If you post there, you will definitely receive a response.
Hey  Dhruv,
I tried to get the verification code for the slack account but the email is
not reaching my inbox, I have checked my spam emails as well but without
confirmation, i cannot get into the slack account,can you please send me
the invitation,i have a few more things to talk as well like the pipenv is
not installing the pipfile,and other stuff regarding the installation for
general API and stuff.

Regards,
Sahil Rasaikar

On Tue, Oct 18, 2022 at 1:53 AM Dhruv Bhanushali ***@***.***>
wrote:

> Hi @sahil-R <https://github.com/sahil-R>, to build the server you do not
> need Pipenv. You can use the Docker-based development setup. Follow the
> steps in our Quickstart guide
> <https://wordpress.github.io/openverse-api/guides/quickstart.html> and
> comment here if you face any issues.
>
> the slack channel is also not working
>
> Can you elaborate on this? To the best of my knowledge the Slack channel
> is very active. If you post there, you will definitely receive a response.
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/WordPress/openverse-api/issues/674#issuecomment-1281446864>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/APGJ2CKGZ7FD4CJAPQELEATWDWYSZANCNFSM5U5ZF5TQ>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>

@sahil-R it's not possible to invite you to the Making WordPress Slack workspace. You'll have to sign up for it by [creating a WordPress.org account](https://login.wordpress.org/register) first and then following the instructions to join Slack on [this page](https://make.wordpress.org/chat/).
Thank you very much,i'll get in touch.
Dhruv, I have updated the tests, and all tests are working fine as messaged you on slack as well, ill  be waiting for the next steps,Thankyou.
Now that you've set up the local stack @sahil-R, the next step would be to remove the `required` prop from the serializers as mentioned in the original issue and open a PR with your changes.

Resolving patch:
diff --git a/api/catalog/api/examples/audio_responses.py b/api/catalog/api/examples/audio_responses.py
--- a/api/catalog/api/examples/audio_responses.py
+++ b/api/catalog/api/examples/audio_responses.py
@@ -22,16 +22,16 @@
     "filesize": 7139840,
     "filetype": "mp3",
     "tags": [
-        {"name": "vocal"},
-        {"name": "female"},
-        {"name": "speed_medium"},
-        {"name": "guitar"},
-        {"name": "strings"},
-        {"name": "energetic"},
-        {"name": "acoustic"},
-        {"name": "vocal"},
-        {"name": "voice"},
-        {"name": "funkyhouse"},
+        {"accuracy": None, "name": "vocal"},
+        {"accuracy": None, "name": "female"},
+        {"accuracy": None, "name": "speed_medium"},
+        {"accuracy": None, "name": "guitar"},
+        {"accuracy": None, "name": "strings"},
+        {"accuracy": None, "name": "energetic"},
+        {"accuracy": None, "name": "acoustic"},
+        {"accuracy": None, "name": "vocal"},
+        {"accuracy": None, "name": "voice"},
+        {"accuracy": None, "name": "funkyhouse"},
     ],
     "alt_files": None,
     "attribution": '"Wish You Were Here" by The.madpix.project is licensed under CC BY-NC-SA 3.0. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/3.0/.',  # noqa: E501,
diff --git a/api/catalog/api/examples/image_responses.py b/api/catalog/api/examples/image_responses.py
--- a/api/catalog/api/examples/image_responses.py
+++ b/api/catalog/api/examples/image_responses.py
@@ -21,27 +21,27 @@
     "filesize": None,
     "filetype": None,
     "tags": [
-        {"name": "tree"},
-        {"name": "bark"},
-        {"name": "texture"},
-        {"name": "wood"},
-        {"name": "nature"},
-        {"name": "pattern"},
-        {"name": "rough"},
-        {"name": "surface"},
-        {"name": "brown"},
-        {"name": "old"},
-        {"name": "background"},
-        {"name": "trunk"},
-        {"name": "natural"},
-        {"name": "forest"},
-        {"name": "detail"},
-        {"name": "lumber"},
-        {"name": "weathered"},
-        {"name": "timber"},
-        {"name": "stump"},
-        {"name": "closeup"},
-        {"name": "root"},
+        {"accuracy": None, "name": "tree"},
+        {"accuracy": None, "name": "bark"},
+        {"accuracy": None, "name": "texture"},
+        {"accuracy": None, "name": "wood"},
+        {"accuracy": None, "name": "nature"},
+        {"accuracy": None, "name": "pattern"},
+        {"accuracy": None, "name": "rough"},
+        {"accuracy": None, "name": "surface"},
+        {"accuracy": None, "name": "brown"},
+        {"accuracy": None, "name": "old"},
+        {"accuracy": None, "name": "background"},
+        {"accuracy": None, "name": "trunk"},
+        {"accuracy": None, "name": "natural"},
+        {"accuracy": None, "name": "forest"},
+        {"accuracy": None, "name": "detail"},
+        {"accuracy": None, "name": "lumber"},
+        {"accuracy": None, "name": "weathered"},
+        {"accuracy": None, "name": "timber"},
+        {"accuracy": None, "name": "stump"},
+        {"accuracy": None, "name": "closeup"},
+        {"accuracy": None, "name": "root"},
     ],
     "attribution": None,
     "fields_matched": [],
diff --git a/api/catalog/api/serializers/media_serializers.py b/api/catalog/api/serializers/media_serializers.py
--- a/api/catalog/api/serializers/media_serializers.py
+++ b/api/catalog/api/serializers/media_serializers.py
@@ -277,9 +277,9 @@ class TagSerializer(serializers.Serializer):
         help_text="The name of a detailed tag.",
     )
     accuracy = serializers.FloatField(
-        required=False,
+        default=None,
         help_text="The accuracy of a machine-generated tag. Human-generated "
-        "tags do not have an accuracy field.",
+        "tags have a null accuracy field.",
     )
 
 


Test patch: