Skip to content

[Fixed #872] Filter Builds according to commit #3544

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

Merged
merged 6 commits into from
Oct 31, 2018
Merged

[Fixed #872] Filter Builds according to commit #3544

merged 6 commits into from
Oct 31, 2018

Conversation

Alig1493
Copy link
Contributor

Added filter fields to api/v2/build/ endpoint to filter according to the commit hashes (Using filter backends).

@Alig1493 Alig1493 changed the title Commit filter [Fixed #872 Filter Builds according to commit] Jan 24, 2018
@Alig1493 Alig1493 changed the title [Fixed #872 Filter Builds according to commit] [Fixed #872] Filter Builds according to commit Jan 24, 2018
@safwanrahman safwanrahman self-requested a review January 24, 2018 17:11
@safwanrahman
Copy link
Member

That looks good @Alig1493. Can you plase add some test for this endpoint filtering?

Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

Thank for your contribution!

I don't really know why, but sometime ago RTD removed django-filter because they stopped using it.

Ref:

It seems that RTD is using just get_queryset methods to do simple filtering now. For example,

https://github.com/rtfd/readthedocs.org/blob/935aa8b37b1b241dff08b968a9bf7dd4ba8347fd/readthedocs/restapi/views/model_views.py#L258-L265

Should we go in that direction? What do you think?

@Alig1493
Copy link
Contributor Author

Alright, since most of the readthedocs code is done that way I think it's also better for me to follow that convention and avoid the django-filters dependency. I will do the necessary corrections.

@safwanrahman
Copy link
Member

I also dont know why django-filters were removed. I am using it quite daily basis in my DRF projects and it seems to be very helpful.
@agjohnson Can you please elaborate why we decided to not use django-filters anymore?

@@ -205,6 +205,13 @@ class BuildViewSetBase(UserSelectViewSet):
admin_serializer_class = BuildAdminSerializer
model = Build

def get_queryset(self):
Copy link
Member

@safwanrahman safwanrahman Feb 13, 2018

Choose a reason for hiding this comment

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

Can you call super instead of making the queryset?
Something like

queryset = super(BuildViewSetBase, self).get_queryset()
commit = self.request.query_params.get('commit', None)
if commit is not None:
    query = query.filter(commit=commit)
    return query

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand and I have looked into it as to why you asked me to do so as well. Your assistance was very well appreciated and I have made the requested changes. You can review it if you wish @safwanrahman.

@safwanrahman
Copy link
Member

@Alig1493 Changes looks good. Can you please add some test for this? Here you can add test

@humitos humitos added PR: work in progress Pull request is not ready for full review and removed PR: ready for review labels Feb 15, 2018
@safwanrahman safwanrahman added PR: ready for review and removed PR: work in progress Pull request is not ready for full review labels Feb 18, 2018
Copy link
Member

@safwanrahman safwanrahman left a comment

Choose a reason for hiding this comment

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

Looks good. r+ from my end

@safwanrahman
Copy link
Member

@humitos Can you please take a look and have a review?

Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

Realized that maybe we need to do more work on this regarding the filtering. I don't know what is the correct solution yet (maybe adding the project slug to the endpoint?)

I think we need more opinions here.

resp = client.get('/api/v2/build/', {'commit': 'test'}, format='json')
self.assertEqual(resp.status_code, 200)
build = resp.data
self.assertEqual(len(build['results']), 1)
Copy link
Member

Choose a reason for hiding this comment

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

I didn't realize this the other day but, is it OK to return a list of one element when we already know that it's going to be always one element?

I suppose it shouldn't be possible to have two different commits with the same hash, right? Although, what would happen for projects that are not git-based? SVN for example which are just plain numbers?

In that case, this endpoint will break (not because the code itself but in meaning, I think)

Copy link
Member

Choose a reason for hiding this comment

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

@humitos As per (build model)[https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/builds/models.py#L430], the commit field is not unique. So theoritically there can be more than one build for same commit. Also, there can be multiple build for same commit like commit get deleted and forced pushed. So I think returning list of builds will be a better idea.

Regarding SVN, I actually do not know whats save in the commit field. Can you please elaborate?

@humitos humitos added the Needed: design decision A core team decision is required label Feb 20, 2018
@safwanrahman
Copy link
Member

@humitos What should we do at this moment? Do you have any idea in your mind?

@ericholscher ericholscher merged commit f56cbd1 into readthedocs:master Oct 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needed: design decision A core team decision is required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants