Convert id arguments to graphene.Int field #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@Chris7 I am on the fence about this one. This is to address ID fields filters being cast as Floats, for example,
users__id
is defined asgraphene.Argument(graphene.Float)
. It becomes an issue when combining multiple queries, that use the same variable to query fields defined either using graphene, graphen-django, or graphql-ruby, and don't apply the same logic to how arguments are defined. So the same variable can be an ID, Int, or Float.The way graphene arguments are created from DRF filters is defined in graphene_django.filter.utils, so this only fixes the ID field generating a Float argument when using graphene-django-extras. Meaning that we probably need to patch
get_filtering_args_from_filterset
locally rather than here as the same issue will come up when somebody attempts to use graphene-django. Also maybe it should call super and do the ID check onargs
afterwards, to avoid redefining the function?Note: I chose Int rather than ID, as I was not quite sure how it would affect number lookups like 'gt', 'lt'
etc. down the line. I can update it to ID for consistency.
But I am not entirely sure wether we should be doing any of this at all. The issue really is that NumberFilter is assigned DecimalField in django-filters. It makes sense that graphene-django assigns it to Float (they just implemented Decimal field, so eventually it would be Decimal). Also, we would still need to ensure that everyone wis using ID and Int arguments consistently.
I do agree that it is counterintuitive that ID arguments are Floats, and there already is a mismatch for
ids
argument, but it is pretty easy (if not very elegant) to work around it in the query by using multiple variables like this: