question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Filtering using Django Integer Choices

See original GitHub issue

Hey guys, I am a real noob with GraphQL, but I think I found a bug, I am trying to filter using an integer choice, below you will see the definitions:

models.py

class Event(models.Model):
    KIND_XXX = 1
    KIND_CHOICES = (
        (KIND_XXX, "Dummy description"),
    )
    name = models.CharField(max_length=35)
    kind = models.IntegerField(choices=KIND_CHOICES)

schema.py

class EventNode(DjangoObjectType):
    class Meta:
        model = Event
        filter_fields = {
            'name': ['exact', 'in', 'icontains', 'istartswith'],
            'kind': ['exact', 'in', 'icontains', 'istartswith'],
        }
        interfaces = (graphene.relay.Node,)

class Query(graphene.ObjectType):
    event = graphene.relay.Node.Field(EventNode)
    all_events = DjangoFilterConnectionField(EventNode)

If I query using name, name__in, etc it works, but when I try to filter by kind__in it says I need an Float which is wrong.

Please note the Float there: image

Result:

{
  "errors": [
    {
      "message": "Argument \"kind_In\" has invalid value \"1\".\nExpected type \"Float\", found \"1\".",
      "locations": [
        {
          "line": 2,
          "column": 22
        }
      ]
    }
  ]
}

As a second help request, I found other issue (but I am not sure if I am misunderstanding something) if I query for a not existent kind it returns the information:

Query for all records…

query{
  allEvents{
    edges{
      node{
        kind
        name
      }
    }
  }
}

Result for all records

{
  "data": {
    "allEvents": {
      "edges": [
        {
          "node": {
            "kind": "A_1",
            "name": "Event X"
          }
        }
      ]
    }
  }
}

Query for not existent kind choice

query{
  allEvents(kind: "2"){
    edges{
      node{
        kind
        name
      }
    }
  }
}

Result for not existent kind choice

{
  "data": {
    "allEvents": {
      "edges": [
        {
          "node": {
            "kind": "A_1",
            "name": "Event X"
          }
        }
      ]
    }
  }
}

I spent like 8 hours debugging, but I couldn’t find any solution, if you can address for a solution, I can PR the fix (in case it is really a bug…,)

Thanks!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
zbyte64commented, May 31, 2019

Dupe of #67

0reactions
changelingcommented, May 30, 2019

The second issue, returning all records as failure mode, may be related to this issue:

DjangoFilterConnectionField and filter_set issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to filter an object with choice filed values in django_filter
and I use django_filters to filter IPInfo. from django_filters import rest_framework as django_filters class IPInfoFilter(django_filters.
Read more >
field_name - django-filter - Read the Docs
This filter matches values in its choices argument. The choices must be explicitly passed when the filter is declared on the FilterSet ....
Read more >
How to filter an object with choice filed values in django_filter ...
You can define a custom method for filtering: class IPInfoFilter(django_filters.FilterSet): ip_type = django_filters.CharFilter(method='filter_ip_type') def ...
Read more >
Developers - Filtering using Django Integer Choices - - Bountysource
Hey guys, I am a real noob with GraphQL, but I think I found a bug, I am trying to filter using an...
Read more >
Handle choices the right way - James Bennett
In Django's ORM , this is represented by using the “choices” argument when defining the field, and generally this provides a fairly easy ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found