Filtering not working correctly with 2.6.0
See original GitHub issueRelated 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:
- Created 4 years ago
- Comments:10 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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 theemail
of theUser
model (which theuser
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 theemail
part of thename
is just ignored. There should actually be some kind of loop to work with filtering on foreign keys.Or am I missing something?
The fix for this has been released: https://github.com/graphql-python/graphene-django/releases/tag/v2.7.0