Skip to content

in filters don't decode IDs #1542

Open
Open
@DrumsnChocolate

Description

@DrumsnChocolate

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(DjangoObjectType):
    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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions