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

restapi: decouple ProjectViewSet from the pk #4192

Closed
wants to merge 1 commit into from

Conversation

xrmx
Copy link
Contributor

@xrmx xrmx commented Jun 6, 2018

We may want to hook the very same viewset under a different
router in order to lookup by slug and not pk. If we use
lookup_field instead of hardcoding it in the views, it becomes
easier.

@xrmx
Copy link
Contributor Author

xrmx commented Jun 6, 2018

As a side note let me add that v1 api has the undocumented property that it supports out of the box using the slug as primary key that the v2 api does not have. And our users like the slug a lot more than the pk.

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.

I'm not convinced this is a good change. It seems like it would change the logic that we're depending on for these API's, unless there's something I'm missing.

readthedocs/restapi/views/model_views.py Show resolved Hide resolved
@xrmx
Copy link
Contributor Author

xrmx commented Jun 7, 2018

Updated the PR after reivew

Copy link
Contributor

@agjohnson agjohnson left a comment

Choose a reason for hiding this comment

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

This is altering our queryset in an insecure way, you should look into the Project querysets to see the use case there. We extend this further with our commercial hosting, so this is a breaking change at the moment.

In general, it's best to start off a pull request as a design discussion first. This sort of issue doesn't benefit our prod environment, so doesn't have a good chance of being merged without discussion first.

Also, because this is off our roadmap, it will be a while before merge. We give precedence to issues and PRs on our roadmap.

@decorators.detail_route()
def valid_versions(self, request, **kwargs):
"""Maintain state of versions that are wanted."""
project = get_object_or_404(
Project.objects.api(request.user), pk=kwargs['pk'])
Copy link
Contributor

Choose a reason for hiding this comment

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

The Project.objects.api queryset is required. This shouldn't be altered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

UserSelectViewSet.get_queryset looks very much the same code

Copy link
Member

Choose a reason for hiding this comment

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

Project.objects.api is overriden in our commercial site to handle different kind of permissions. That's the problem here.

This is the code used to extend this class from outside:

https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/projects/querysets.py#L66-L69

Even if get_queryset is too similar here, it will break our commercial site and we will need to refactor that code also.

I hope that helps you to understand why we can't accept this change for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What am trying to tell you is that UserSelectViewSet.get_queryset is a fancy way to write return Project.objects.api(self.request.user).
https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/restapi/views/model_views.py#L79

@agjohnson agjohnson added this to the Development improvements milestone Jun 8, 2018
@xrmx
Copy link
Contributor Author

xrmx commented Jun 11, 2018

Can we have the request changes removed reconsidered after my answer please?

@xrmx
Copy link
Contributor Author

xrmx commented Jun 26, 2018

Ping :)

@xrmx
Copy link
Contributor Author

xrmx commented Jul 4, 2018

@agjohnson care to reconsider your review after #4192 (comment) please?

This one would make #4286 trivial for projects endpoints at least

@xrmx
Copy link
Contributor Author

xrmx commented Jul 18, 2018

Ping

@safwanrahman
Copy link
Member

safwanrahman commented Jul 18, 2018

@xrmx its in our radar. please wait some days!

@humitos
Copy link
Member

humitos commented Dec 3, 2018

I'm not convinced yet that this is something that we need to change in our code base.

We may want to hook the very same viewset under a different router in order to lookup by slug and not pk

Because of this problem, among others, we are creating APIv3. So, if this PR doesn't fix a bug I think we shouldn't make this changes to be able to extend the API code for something that will be covered in APIv3 and put this energy in that PR instead.

@xrmx
Copy link
Contributor Author

xrmx commented Dec 3, 2018

@humitos This PR cleans the code up to make it reusable instead of requiring people to copy & paste it. It's not extending the API so it's not adding more maintenance burden for you.
So while these changes don't fix any bug, they help reducing the downstream diff so that it would be easier to track upstream and forward fixes and features back.

@xrmx
Copy link
Contributor Author

xrmx commented Jan 1, 2019

Rebased to fix conflict errors

@stale
Copy link

stale bot commented Feb 15, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: stale Issue will be considered inactive soon label Feb 15, 2019
We may want to hook the very same viewset under a different
router in order to lookup by slug and not pk. If we use
lookup_field instead of hardcoding it in the views, it becomes
easier. While at it reuse get_queryset() method for filtering
the queryset.
@stale stale bot removed the Status: stale Issue will be considered inactive soon label Feb 15, 2019
@xrmx
Copy link
Contributor Author

xrmx commented Feb 15, 2019

Rebased, any chance this can be merged please?

@stale
Copy link

stale bot commented Apr 1, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: stale Issue will be considered inactive soon label Apr 1, 2019
@stale stale bot closed this Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: stale Issue will be considered inactive soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants