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 not working correctly with 2.6.0

See original GitHub issue

Related to #750. Appreciate the fix for this problem!!

Problem

When using filter_fields I get an error about using wrong types which started appearing in 2.4.0. Variable "userEmail" of type "String" used in position expecting type "ID". The error does not occur with graphene-django 2.3.2

Context

  • using django-filter 2.2.0
  • django 2.4.0
  • graphene-django 2.6.0

model.py

class Membership(TimeStampedModel):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE)



class User(TimeStampedModel, AbstractBaseUser, PermissionsMixin):
    email = EmailField(unique=True, verbose_name=_('email'))

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

    objects = UserManager()

Schema.py

class MembershipNode(DjangoObjectType):
    class Meta:
        model = Membership
        filter_fields = {
            'id': ['exact'],
            'user__email': ['exact'],
        }
        interfaces = (MembershipNodeInterface,)

Query:

QUERY_MEMBERSHIPS = '''
    query memberships($tenant: String!, $userEmail: String) {
        memberships(tenant: $tenant, user_Email: $userEmail) {
            edges {
                node {
                    id
                    isFitter
                    isMonitor
                    isAdmin
                    isStaff
                }
            }
        }
    }
'''

Result: Variable "userEmail" of type "String" used in position expecting type "ID".

Solution

Should be related to #750. Might be a special case due to the email being the identifying field of the User

I am confident it is related to this PR: https://github.com/graphql-python/graphene-django/pull/682/files . In graphene_django/filter/utils.py the way how to retrieve the Type of a field was changed.

Keep on rocking 😃

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
lassesteffencommented, Sep 24, 2019

I see why it’s doing what it does. It is not coded to work with filtering on foreign keys, which is the problem here. Because the user field on Membership is indeed of type ID. But the problem is I am actually trying to filter by the email of the User model (which the user field is linking to.)
The split in line 21 in utils.py breaks it, since it is written under the assumption that there are no accesses to foreign keys, and the email part of the name is just ignored. There should actually be some kind of loop to work with filtering on foreign keys.
Or am I missing something?

0reactions
jkimbocommented, Nov 28, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Filter not working - WordPress.org
Hello,. On our website the product filter plugin suddenly doesn't work anymore. I tried rolling back some plugin's, but that doesn't fix the...
Read more >
Product filter does not show filters or not working for attributes ...
Product filter does not show filters or not working for attributes / categories / tags only with WooCommerce between 2.6.x and 3.0 and...
Read more >
IP block logging not working pfSense 2.6.0-RC : r/pfBlockerNG
It seems that ip_block.log is not filled anymore. In 2.5.2 this is working correctly and i've changed nothing in the settings. Is this...
Read more >
Excel filter not working after certain row - YouTube
00:00 Filter missing rows 00:30 Reason it is missing- your filter set up 01:08 Correct way to set up filter … Show more....
Read more >
java - Maven clean install: Failed to execute goal org.apache ...
3. The problem is that items being filtered which should not being filter. · 2. No that work-a-round covers a problem with filtering......
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