-
Notifications
You must be signed in to change notification settings - Fork 50
Overhaul serializers to eliminate manually defined fields #696
Conversation
API Developer Docs Preview: Ready https://wordpress.github.io/openverse-api/_preview/696 Please note that GitHub pages takes a little time to deploy newly pushed code, if the links above don't work or you see old versions, wait 5 minutes and try again. You can check the GitHub pages deployment action list to see the current status of the deployments. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The clean up so far looks really nice but I wonder if we could wait to do this until we have unit tested the serializers in #557?
@sarayourfriend since the output is not being changed, I'd recommend WordPress/openverse#724 proceed with the tests based on serializers as on Also there will be changes to the tests needed when #684 gets merged. |
Okay! I was mostly trying to get around at least three of us going through each API endpoint and verifying it works locally 😅 |
3d68558
to
d83b73c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are there new fields being returned/present on the image respones?
tags = models.JSONField( | ||
blank=True, | ||
null=True, | ||
help_text="Tags with detailed metadata, such as accuracy.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is "accuracy"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accuracy is present on old tags that have clarifai
as provider. The docstrings:
"The accuracy of a machine-generated tag. Human-generated tags do not have an accuracy field."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh. Could we clarify what accuracy
means here then? Maybe such as accuracy in the case of clarifai provided tags
or something? Or just not call out a specific field at all, if that's too cumbersome.
This mixin adds | ||
|
||
- foreign_identifier: CharField |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the goal of this type of comment? It seems like it just duplicates the information that's already documented declaratively in the class definition below it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is helpful when you're reading a class and hover over the name of its mixins to see what fields they're adding to the model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. My concern is that because it is essentially a 1:1 mirror of the implementation that it will easily go out of date quickly (as it already had, with this line needing to be move from one serializer to another without any changes on the actual implementation of either one).
If our base mixin classes are so abstract that it's not easy to remember (or learn) what fields they provide based on the names and reading the declarative code inside their definitions, maybe it's a sign that things are too complex?
It could be I'm over thinking this though. I'm just wary of whenever we start to hand write and hand-maintain documentation that says in literal terms what the code immediately below it says.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this either, and I'm 100% in agreement with you that the mixins are super-confusing and can be improved. If we did spend a lot of time in the API models (which we don't), we'd soon remember what field was where.
But at the moment, it's a bit hard to see a class inheriting from 4-5 mixins and having to guess which fields are coming from which mixin (or going to each of their definitions to check).
^ That was an accident, sorry. |
The goal was to ensure that the search results and the details endpoint should follow as close a schema as possible by avoiding the use of |
Makes sense, thanks for the explanation. What's the testing strategy for this? I saw that the "visit each endpoint and verify it" is crossed out. But the sample responses aren't automatically generated are they? Is anything comparing those against the actual data coming from the API this PR produces? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested the API locally and see that the issue that we saw in production is gone. It's a huge improvement, thank you for adding all the documentation in the docstrings!
@sarayourfriend the example responses are compared by actually making a request to the API and checking if the JSON matches exactly. It tests the API by checking both search results and detail pages. |
I'm merging this to unblock API deployment. We can surely fix any smaller issues that come up in hotfixes. |
Sounds good @dhruvkb 👍 |
Description
To further streamline the process of adding new media, this PR updates serializers to almost eliminate manually defined serializer fields.
This PR
help_text
from serializers to modelsTesting Instructions
Being a refactoring PR, the differences at the surface level should be minimal. To test, visit each endpoint once (sorry for the big ask) and see that the server never raises any errors or sends a 500 status code.You can also see the changes to
api/catalog/api/examples/image_responses.py
andapi/catalog/api/examples/audio_responses.py
to see the final output changes.Checklist
Update index.md
).main
) or a parent feature branch.Developer Certificate of Origin
Developer Certificate of Origin