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

Filter by id causes other filters to be ignored #148

Closed
claradaia opened this issue Jun 4, 2020 · 3 comments
Closed

Filter by id causes other filters to be ignored #148

claradaia opened this issue Jun 4, 2020 · 3 comments

Comments

@claradaia
Copy link
Contributor

claradaia commented Jun 4, 2020

Hello, I find that if I make a query with a filter by id, other filters are ignored. For example, in the following query:

query players {{
    players(
        id: "UmVwb3J0ZXJOb2RlOjE=",  # id of some player with first_name == "Larry"
        firstName: "Michael"
    ) {{
        edges {{
            node {{
                id
                firstName
            }}
        }}
    }}
}}

I expected an empty list, because the filters should "cancel", but it actually retrieves the "Larry" player.

I created a PR with a test case that reproduces this -- only in relay, but I can check if it happens without relay too.

Is it supposed to be this way? If not, I can try and fix it next week.

@claradaia
Copy link
Contributor Author

Ok, so I checked the commit history and apparently this commit introduces this new "if" that uses get_node_from_global_id and returns the node if id is present in the filters. I believe this excerpt:

        _id = args.pop('id', None)

        if _id is not None:
            iterables = [get_node_from_global_id(self.node_type, info, _id)]
            list_length = 1
        elif callable(getattr(self.model, "objects", None)):
            iterables = self.get_queryset(self.model, info, **args)
            list_length = iterables.count()
        else:
            iterables = []
            list_length = 0

should be changed to

        _id = args.pop('id', None)
        # code that existed before to replace the id filter with 'pk'
        if _id is not None:
                args['pk'] = global_id_via_node(self.node_type, _id)[-1]

        if callable(getattr(self.model, "objects", None)):
            iterables = self.get_queryset(self.model, info, **args)
            list_length = iterables.count()
        else:
            iterables = []
            list_length = 0

Thoughts?

@claradaia
Copy link
Contributor Author

claradaia commented Jun 26, 2020

I updated the PR with something similar and my test case passed, please let me know if there's a better way to do it.

@abawchen
Copy link
Collaborator

@claradaia : Thanks for the PR, and it looks good to me. Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants