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

in filters don't decode IDs #1542

Open
DrumsnChocolate opened this issue Feb 6, 2025 · 0 comments
Open

in filters don't decode IDs #1542

DrumsnChocolate opened this issue Feb 6, 2025 · 0 comments
Labels

Comments

@DrumsnChocolate
Copy link

DrumsnChocolate commented Feb 6, 2025

Note: for support questions, please use stackoverflow. This repository's issues are reserved for feature requests and bug reports.

  • What is the current behavior?

Using django-filter for filtering an exact ID match functions well, while filtering for an id in some set of IDs does not.

For AutoFields and ForeignKeys and the like, when specifying "id": ["exact", "in"] as part of a node's filter_fields, the exact filter works well, while the in filter raises exceptions resulting from not decoding global ids.

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

via a github repo, https://repl.it or similar (you can use this template as a starting point: https://repl.it/@jkimbo/Graphene-Django-Example).

If you'd like, I can setup a repl.it example, but for now I'll just illustrate here:

class Apple(models.Model):
    colour = models.CharField(max_length=7)

class AppleType(DjangoObjecType):
    class Meta:
        model = Apple
        fields = ("id", "colour")
        filter_fields = {"id": ["exact", "in"]}
        interfaces = (graphene.relay.Node,)

class Query(graphene.ObjectType):
    apples = DjangoFilterConnectionField(AppleType)

And then a query like

query getApples($id: ID) {
    apples(id: $id) {
        id
        colour
    }
}

works fine, while

query getApplesIn($id__in: [ID]) {
    apples(id__in: $id__in) {
        id
        colour
    }
}

does not.

  • What is the expected behavior?
    The latter query should return the objects that match the specified list of IDs.

  • What is the motivation / use case for changing the behavior?
    I think this is a bug/oversight.

  • Please tell us about your environment:

    • Version: 3.2.2
    • Platform: macOS 15.3 (but I've also experienced this on manjaro, this is not OS specific)
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow)
    If this is the type of bug you would fix, I can provide a reproducible example.

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

No branches or pull requests

1 participant