{"action":"created","comment":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/106479643","pull_request_review_id":27399408,"id":106479643,"diff_hunk":"@@ -3,10 +3,36 @@\n \n from modularodm import Q\n \n-from api.base.exceptions import InvalidFilterError\n+from api.base.exceptions import InvalidFilterError, InvalidFilterValue\n from api.base.filters import ODMFilterMixin\n from api.base import utils\n \n+from osf.models import AbstractNode as Node\n+\n+\n+class NodesListFilterMixin(ODMFilterMixin):\n+\n+    def _operation_to_query(self, operation):\n+        # We special case filters on root because root isn't a field; to get the children\n+        # of a root, we use a custom manager method, Node.objects.get_children, and build\n+        # a query from that\n+        if operation['source_field_name'] == 'root':\n+            child_pks = []\n+            for root_guid in operation['value']:\n+                if not root_guid:\n+                    raise InvalidFilterValue(value=root_guid)\n+                root = utils.get_object_or_error(Node, root_guid, display_name='root', prefetch_fields=self.serializer_class().model_field_names)\n+                child_pks.extend(Node.objects.get_children(root=root, primary_keys=True))\n+            return Q('id', 'in', child_pks)\n+        elif operation['source_field_name'] == 'parent_node':","path":"api/nodes/filters.py","position":26,"original_position":26,"commit_id":"e6f23067a6c8f6a273d00a98eae6f0e78b674b97","original_commit_id":"e6f23067a6c8f6a273d00a98eae6f0e78b674b97","user":{"login":"sloria","id":2379650,"avatar_url":"https://avatars1.githubusercontent.com/u/2379650?v=3","gravatar_id":"","url":"https://api.github.com/users/sloria","html_url":"https://github.com/sloria","followers_url":"https://api.github.com/users/sloria/followers","following_url":"https://api.github.com/users/sloria/following{/other_user}","gists_url":"https://api.github.com/users/sloria/gists{/gist_id}","starred_url":"https://api.github.com/users/sloria/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sloria/subscriptions","organizations_url":"https://api.github.com/users/sloria/orgs","repos_url":"https://api.github.com/users/sloria/repos","events_url":"https://api.github.com/users/sloria/events{/privacy}","received_events_url":"https://api.github.com/users/sloria/received_events","type":"User","site_admin":false},"body":"Maybe `Q('parent_nodes__guids___id', 'eq', parent_guid)`?","created_at":"2017-03-16T17:22:38Z","updated_at":"2017-03-16T17:22:52Z","html_url":"https://github.com/CenterForOpenScience/osf.io/pull/6940#discussion_r106479643","pull_request_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/6940","_links":{"self":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments/106479643"},"html":{"href":"https://github.com/CenterForOpenScience/osf.io/pull/6940#discussion_r106479643"},"pull_request":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/6940"}}},"pull_request":{"url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/6940","id":109338951,"html_url":"https://github.com/CenterForOpenScience/osf.io/pull/6940","diff_url":"https://github.com/CenterForOpenScience/osf.io/pull/6940.diff","patch_url":"https://github.com/CenterForOpenScience/osf.io/pull/6940.patch","issue_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/6940","number":6940,"state":"open","locked":false,"title":"Fix Parent Filtering on Nodes [OSF-7578]","user":{"login":"caseyrollins","id":7913604,"avatar_url":"https://avatars3.githubusercontent.com/u/7913604?v=3","gravatar_id":"","url":"https://api.github.com/users/caseyrollins","html_url":"https://github.com/caseyrollins","followers_url":"https://api.github.com/users/caseyrollins/followers","following_url":"https://api.github.com/users/caseyrollins/following{/other_user}","gists_url":"https://api.github.com/users/caseyrollins/gists{/gist_id}","starred_url":"https://api.github.com/users/caseyrollins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caseyrollins/subscriptions","organizations_url":"https://api.github.com/users/caseyrollins/orgs","repos_url":"https://api.github.com/users/caseyrollins/repos","events_url":"https://api.github.com/users/caseyrollins/events{/privacy}","received_events_url":"https://api.github.com/users/caseyrollins/received_events","type":"User","site_admin":false},"body":"#### Purpose\r\n- Filtering nodes by parent node is broken on the user nodes list view (`/v2/users/me/nodes/`) and institution nodes list view (`/v2/institutions/<id>/nodes/`). \r\n  - Both routes currently return a `502` on staging.\r\n- Filtering by a parent node works as expected on the nodes list view (`/v2/nodes/`) because of the ODM filter logic [here](https://github.com/CenterForOpenScience/osf.io/blob/develop/api/nodes/views.py#L297).\r\n- Filtering registrations by parent is also broken.\r\n\r\n#### Changes\r\n- Adds a `NodesListFilterMixin` class that contains the [existing logic](https://github.com/CenterForOpenScience/osf.io/blob/develop/api/nodes/views.py#L297) for the parent filter to work correctly. \r\n- Adds the `NodesListFilterMixin` class to views that return a serialized list of nodes/registrations (nodes list, institution nodes list, user nodes list, registrations list).\r\n- Adds `NodesListFilteringMixin` and `RegistrationListFilteringMixin` classes to test filtering on the views mentioned above.\r\n\r\n#### Side effects\r\n- None expected.\r\n\r\n#### Ticket\r\n- [OSF-7578](https://openscience.atlassian.net/browse/OSF-7578)\r\n","created_at":"2017-03-06T20:13:44Z","updated_at":"2017-03-16T17:22:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bb6dc24dbc67cd5932f4e1e45b35dca6747e2ab9","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/6940/commits","review_comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/6940/comments","review_comment_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments{/number}","comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/6940/comments","statuses_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/e6f23067a6c8f6a273d00a98eae6f0e78b674b97","head":{"label":"caseyrollins:feature/fix-parent-filtering","ref":"feature/fix-parent-filtering","sha":"e6f23067a6c8f6a273d00a98eae6f0e78b674b97","user":{"login":"caseyrollins","id":7913604,"avatar_url":"https://avatars3.githubusercontent.com/u/7913604?v=3","gravatar_id":"","url":"https://api.github.com/users/caseyrollins","html_url":"https://github.com/caseyrollins","followers_url":"https://api.github.com/users/caseyrollins/followers","following_url":"https://api.github.com/users/caseyrollins/following{/other_user}","gists_url":"https://api.github.com/users/caseyrollins/gists{/gist_id}","starred_url":"https://api.github.com/users/caseyrollins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caseyrollins/subscriptions","organizations_url":"https://api.github.com/users/caseyrollins/orgs","repos_url":"https://api.github.com/users/caseyrollins/repos","events_url":"https://api.github.com/users/caseyrollins/events{/privacy}","received_events_url":"https://api.github.com/users/caseyrollins/received_events","type":"User","site_admin":false},"repo":{"id":26963858,"name":"osf.io","full_name":"caseyrollins/osf.io","owner":{"login":"caseyrollins","id":7913604,"avatar_url":"https://avatars3.githubusercontent.com/u/7913604?v=3","gravatar_id":"","url":"https://api.github.com/users/caseyrollins","html_url":"https://github.com/caseyrollins","followers_url":"https://api.github.com/users/caseyrollins/followers","following_url":"https://api.github.com/users/caseyrollins/following{/other_user}","gists_url":"https://api.github.com/users/caseyrollins/gists{/gist_id}","starred_url":"https://api.github.com/users/caseyrollins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/caseyrollins/subscriptions","organizations_url":"https://api.github.com/users/caseyrollins/orgs","repos_url":"https://api.github.com/users/caseyrollins/repos","events_url":"https://api.github.com/users/caseyrollins/events{/privacy}","received_events_url":"https://api.github.com/users/caseyrollins/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/caseyrollins/osf.io","description":"Facilitating Open Science","fork":true,"url":"https://api.github.com/repos/caseyrollins/osf.io","forks_url":"https://api.github.com/repos/caseyrollins/osf.io/forks","keys_url":"https://api.github.com/repos/caseyrollins/osf.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/caseyrollins/osf.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/caseyrollins/osf.io/teams","hooks_url":"https://api.github.com/repos/caseyrollins/osf.io/hooks","issue_events_url":"https://api.github.com/repos/caseyrollins/osf.io/issues/events{/number}","events_url":"https://api.github.com/repos/caseyrollins/osf.io/events","assignees_url":"https://api.github.com/repos/caseyrollins/osf.io/assignees{/user}","branches_url":"https://api.github.com/repos/caseyrollins/osf.io/branches{/branch}","tags_url":"https://api.github.com/repos/caseyrollins/osf.io/tags","blobs_url":"https://api.github.com/repos/caseyrollins/osf.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/caseyrollins/osf.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/caseyrollins/osf.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/caseyrollins/osf.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/caseyrollins/osf.io/statuses/{sha}","languages_url":"https://api.github.com/repos/caseyrollins/osf.io/languages","stargazers_url":"https://api.github.com/repos/caseyrollins/osf.io/stargazers","contributors_url":"https://api.github.com/repos/caseyrollins/osf.io/contributors","subscribers_url":"https://api.github.com/repos/caseyrollins/osf.io/subscribers","subscription_url":"https://api.github.com/repos/caseyrollins/osf.io/subscription","commits_url":"https://api.github.com/repos/caseyrollins/osf.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/caseyrollins/osf.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/caseyrollins/osf.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/caseyrollins/osf.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/caseyrollins/osf.io/contents/{+path}","compare_url":"https://api.github.com/repos/caseyrollins/osf.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/caseyrollins/osf.io/merges","archive_url":"https://api.github.com/repos/caseyrollins/osf.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/caseyrollins/osf.io/downloads","issues_url":"https://api.github.com/repos/caseyrollins/osf.io/issues{/number}","pulls_url":"https://api.github.com/repos/caseyrollins/osf.io/pulls{/number}","milestones_url":"https://api.github.com/repos/caseyrollins/osf.io/milestones{/number}","notifications_url":"https://api.github.com/repos/caseyrollins/osf.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/caseyrollins/osf.io/labels{/name}","releases_url":"https://api.github.com/repos/caseyrollins/osf.io/releases{/id}","deployments_url":"https://api.github.com/repos/caseyrollins/osf.io/deployments","created_at":"2014-11-21T14:49:09Z","updated_at":"2016-01-20T14:34:47Z","pushed_at":"2017-03-14T20:00:08Z","git_url":"git://github.com/caseyrollins/osf.io.git","ssh_url":"git@github.com:caseyrollins/osf.io.git","clone_url":"https://github.com/caseyrollins/osf.io.git","svn_url":"https://github.com/caseyrollins/osf.io","homepage":"http://osf.io","size":148379,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"CenterForOpenScience:develop","ref":"develop","sha":"b8510983c2b41ae7c034a478c6643d3ede7f82c5","user":{"login":"CenterForOpenScience","id":3344584,"avatar_url":"https://avatars2.githubusercontent.com/u/3344584?v=3","gravatar_id":"","url":"https://api.github.com/users/CenterForOpenScience","html_url":"https://github.com/CenterForOpenScience","followers_url":"https://api.github.com/users/CenterForOpenScience/followers","following_url":"https://api.github.com/users/CenterForOpenScience/following{/other_user}","gists_url":"https://api.github.com/users/CenterForOpenScience/gists{/gist_id}","starred_url":"https://api.github.com/users/CenterForOpenScience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CenterForOpenScience/subscriptions","organizations_url":"https://api.github.com/users/CenterForOpenScience/orgs","repos_url":"https://api.github.com/users/CenterForOpenScience/repos","events_url":"https://api.github.com/users/CenterForOpenScience/events{/privacy}","received_events_url":"https://api.github.com/users/CenterForOpenScience/received_events","type":"Organization","site_admin":false},"repo":{"id":10199599,"name":"osf.io","full_name":"CenterForOpenScience/osf.io","owner":{"login":"CenterForOpenScience","id":3344584,"avatar_url":"https://avatars2.githubusercontent.com/u/3344584?v=3","gravatar_id":"","url":"https://api.github.com/users/CenterForOpenScience","html_url":"https://github.com/CenterForOpenScience","followers_url":"https://api.github.com/users/CenterForOpenScience/followers","following_url":"https://api.github.com/users/CenterForOpenScience/following{/other_user}","gists_url":"https://api.github.com/users/CenterForOpenScience/gists{/gist_id}","starred_url":"https://api.github.com/users/CenterForOpenScience/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CenterForOpenScience/subscriptions","organizations_url":"https://api.github.com/users/CenterForOpenScience/orgs","repos_url":"https://api.github.com/users/CenterForOpenScience/repos","events_url":"https://api.github.com/users/CenterForOpenScience/events{/privacy}","received_events_url":"https://api.github.com/users/CenterForOpenScience/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/CenterForOpenScience/osf.io","description":"Facilitating Open Science","fork":false,"url":"https://api.github.com/repos/CenterForOpenScience/osf.io","forks_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/forks","keys_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/teams","hooks_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/hooks","issue_events_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/events{/number}","events_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/events","assignees_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/assignees{/user}","branches_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/branches{/branch}","tags_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/tags","blobs_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/{sha}","languages_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/languages","stargazers_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/stargazers","contributors_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/contributors","subscribers_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/subscribers","subscription_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/subscription","commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/contents/{+path}","compare_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/merges","archive_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/downloads","issues_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues{/number}","pulls_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls{/number}","milestones_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/milestones{/number}","notifications_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/labels{/name}","releases_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/releases{/id}","deployments_url":"https://api.github.com/repos/CenterForOpenScience/osf.io/deployments","created_at":"2013-05-21T15:53:37Z","updated_at":"2017-03-16T16:55:18Z","pushed_at":"2017-03-16T17:10:56Z","git_url":"git://github.com/CenterForOpenScience/osf.io.git","ssh_url":"git@github.com:CenterForOpenScience/osf.io.git","clone_url":"https://github.com/CenterForOpenScience/osf.io.git","svn_url":"https://github.com/CenterForOpenScience/osf.io","homepage":"https://osf.io","size":150220,"stargazers_count":307,"watchers_count":307,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":218,"mirror_url":null,"open_issues_count":237,"forks":218,"open_issues":237,"watchers":307,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/6940"},"html":{"href":"https://github.com/CenterForOpenScience/osf.io/pull/6940"},"issue":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/6940"},"comments":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/issues/6940/comments"},"review_comments":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/6940/comments"},"review_comment":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/pulls/6940/commits"},"statuses":{"href":"https://api.github.com/repos/CenterForOpenScience/osf.io/statuses/e6f23067a6c8f6a273d00a98eae6f0e78b674b97"}}}}
{"actor":{"display_login":"sloria"}}