Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Django form / DRF decimals to Graphene decimals #958

Merged
merged 3 commits into from
Jan 10, 2021

Conversation

ulgens
Copy link
Collaborator

@ulgens ulgens commented May 11, 2020

Fixes #91

(Branch name is outdated. I can create a new PR if it's necessary.)

@ulgens ulgens force-pushed the register_decimal_as_string branch 2 times, most recently from b3e60eb to 7cd95a4 Compare May 22, 2020 03:22
@ulgens ulgens force-pushed the register_decimal_as_string branch 2 times, most recently from 95ad7e5 to 2ab41dd Compare July 15, 2020 07:17
@ulgens ulgens force-pushed the register_decimal_as_string branch 2 times, most recently from ab9143f to 827f918 Compare August 12, 2020 18:10
@zbyte64
Copy link
Collaborator

zbyte64 commented Dec 31, 2020

#91 is fixed, is this still relevant? What's this about test_should_query_filter_node_limit ?

@ulgens
Copy link
Collaborator Author

ulgens commented Dec 31, 2020

@zbyte64 I don't think this is still relevant, i'll test and update it asap. The issue with the test, as far as i remember, registering a decimal as string affected incoming data type in pagination, paginator was expecting a decimal value (not sure how and why).

@zbyte64 zbyte64 changed the base branch from master to v2 December 31, 2020 06:50
@ulgens
Copy link
Collaborator Author

ulgens commented Jan 2, 2021

@zbyte64 This is still relevant. #1083 doesn't touch Django form based conversions at all. I'll try to make it work with that new graphene.Decimal type.

@ulgens ulgens changed the title Register decimals as string Convert Django form decimals to Graphene decimals Jan 2, 2021
@ulgens ulgens marked this pull request as ready for review January 2, 2021 01:23
@ulgens ulgens requested a review from zbyte64 January 2, 2021 01:25
@@ -671,7 +671,7 @@ def resolve_all_reporters(self, info, **args):
schema = Schema(query=Query)
query = """
query NodeFilteringQuery {
allReporters(limit: 1) {
allReporters(limit: "1") {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zbyte64 I couldn't understand why this change is necessary and i can use some help 🙂

The filter here uses NumberFilter from django-filters and it expects a decimal input. Decimal(1) == Decimal("1") is true but when that input is numeric 1, the test fails with

FAILED graphene_django/filter/tests/test_fields.py::test_should_query_filter_node_limit - assert not [GraphQLError('Argument "limit" has invalid value 1.\nExpected type "Decimal", found 1.')]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I experimented with adding the following above line 671:

assert Query.all_reporters.filtering_args["limit"].type is Decimal, str(
        Query.all_reporters.filtering_args["limit"].type
    )

Interestingly this line did not fail. So we know we're generating the right graphene type at least.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is easier to get a stack trace with v3 than v2, still working on this :/

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something interesting happened when I branched and rebased off v3, that particular error went away but then it stopped applying the limit, filter_limit no longer gets called. BUT if I then switch the form conversion back to float the method gets called by django filter. Digging further the args being passed into DjangoFilterConnectoinField.resolve_queryset as limit as None when we convert to Decimal but not Float.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Traced the issue to graphene, I'll be sending them a PR in a moment

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should fix the issue we were seeing: graphql-python/graphene#1295

@ulgens ulgens changed the title Convert Django form decimals to Graphene decimals Convert Django form / DRF decimals to Graphene decimals Jan 2, 2021
Copy link
Member

@jkimbo jkimbo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks @ulgens

(this should probably be part of the v3 release since it's a breaking change)

@zbyte64 zbyte64 merged commit 66c8901 into v2 Jan 10, 2021
@zbyte64 zbyte64 deleted the register_decimal_as_string branch January 10, 2021 06:00
@ulgens
Copy link
Collaborator Author

ulgens commented Jan 10, 2021

@zbyte64 Why did we just merge it? 🙂 graphene didn't release a v2 version with decimal fix. I was intended to revert 1 -> "1" after that fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert DecimalField to String rather than Float
3 participants