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

Build details page: normalize/trim command paths (second attempt) #9831

Merged
merged 6 commits into from
Dec 22, 2022

Conversation

humitos
Copy link
Member

@humitos humitos commented Dec 21, 2022

Continuation of the work done in
#9815 that didn't work as we
expected.

We weren't saving the commands properly when hitting the API since
serializers.SerializerMethodField is a read-only field. This commit fixes this
problem by using a different Serializer depending if it's a GET request or not,
and if it's made by an Admin or not.

It overrides the method BuildViewSet.get_serializer_class to manage these
different cases and return the proper serializer.

Done on top of #9827 to be sure the
tests for saving commands are passing.

Closes #9833

@humitos humitos requested a review from a team as a code owner December 21, 2022 11:01
Continuation of the work done in
#9815 that didn't work as we
expected.

We weren't saving the commands properly when hitting the API since
`serializers.SerializerMethodField` is a read-only field. This commit fixes this
problem by using a different Serializer depending if it's a GET request or not,
and if it's made by an Admin or not.

It overrides the method `BuildViewSet.get_serializer_class` to manage these
different cases and return the proper serializer.

Done on top of #9827 to be sure the
tests for saving commands are passing.
@humitos humitos force-pushed the humitos/build-trim-get-commands branch from 7c8c4f3 to a40a329 Compare December 21, 2022 11:03
@humitos humitos changed the title API V2: test that command is actually saved Build details page: normalize/trim command paths (second attempt) Dec 21, 2022
Copy link
Member

@stsewd stsewd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also be implemented for the command API? https://readthedocs.org/api/v2/command/174704149/

Don't think we use that from our dashboard, but it will make the API consistent.

readthedocs/api/v2/views/model_views.py Outdated Show resolved Hide resolved
readthedocs/api/v2/serializers.py Outdated Show resolved Hide resolved
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it will fix the issue, along with @stsewd's feedback 👍

readthedocs/api/v2/serializers.py Outdated Show resolved Hide resolved
readthedocs/api/v2/serializers.py Outdated Show resolved Hide resolved
readthedocs/api/v2/views/model_views.py Outdated Show resolved Hide resolved
@humitos
Copy link
Member Author

humitos commented Dec 22, 2022

@stsewd

Should this also be implemented for the command API?
Don't think we use that from our dashboard, but it will make the API consistent.

I wasn't sure about this since we are not using it anywhere AFAIK, APIv2 is already deprecated and users shouldn't be using it. The main idea was to make the dashboard UI better for now without going too deep. If we want to follow that road, we should do it for APIv3 as well (but it will change the behavior, so 🤷🏼 ) and review all the places where they are used.

I think it may be fine to not implement it on the command API for now; but I'm open to other arguments.

- rename serializer to mention "ReadOnly" on it's class name
- add docstrings to these serializers
@humitos
Copy link
Member Author

humitos commented Dec 22, 2022

Thanks for the feedback! I think I've addressed all of it. Let me know.

@stsewd I renamed the serializer class to mention "ReadOnly" on its name.

@ericholscher I added docstring to the classes --hopefully, it's a little more clear now.

Old builds don't have the builder hash in the docroot, since that was implmented
recently.
Copy link
Contributor

@benjaoming benjaoming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to have this merged, and all the other feedback is resolved, so 👍 great work on adding comments!

readthedocs/api/v2/serializers.py Outdated Show resolved Hide resolved
readthedocs/api/v2/views/model_views.py Outdated Show resolved Hide resolved
Co-authored-by: Benjamin Balder Bach <[email protected]>
@benjaoming benjaoming merged commit a04df36 into test-command-save Dec 22, 2022
@benjaoming benjaoming deleted the humitos/build-trim-get-commands branch December 22, 2022 17:32
@ericholscher
Copy link
Member

ericholscher commented Dec 22, 2022

@ericholscher I added docstring to the classes --hopefully, it's a little more clear now.

@humitos Much clearer what is happening. Thanks! 💯

stsewd added a commit that referenced this pull request Dec 22, 2022
* API V2: test that command is actually saved

* Build details page: normalize/trim command paths (second attempt) (#9831)

Continuation of the work done in
#9815 that didn't work as we
expected.

We weren't saving the commands properly when hitting the API since
`serializers.SerializerMethodField` is a read-only field. This commit fixes this
problem by using a different Serializer depending if it's a GET request or not,
and if it's made by an Admin or not.

It overrides the method `BuildViewSet.get_serializer_class` to manage these
different cases and return the proper serializer.

Done on top of #9827 to be sure the
tests for saving commands are passing.

* Feedback from review addressed

- rename serializer to mention "ReadOnly" on it's class name
- add docstrings to these serializers

* Typo when accessing the action

* Optional builder hash on local instance

Old builds don't have the builder hash in the docroot, since that was implmented
recently.

Co-authored-by: Manuel Kaufmann <[email protected]>
Co-authored-by: Benjamin Balder Bach <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants