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

InputObjectType causing encoding issues with JSONField #1389

Open
adilhussain540 opened this issue Feb 15, 2023 · 0 comments
Open

InputObjectType causing encoding issues with JSONField #1389

adilhussain540 opened this issue Feb 15, 2023 · 0 comments
Labels

Comments

@adilhussain540
Copy link

Note: for support questions, please use stackoverflow. This repository's issues are reserved for feature requests and bug reports.

  • What is the current behavior?
    I have an InputObjectType with multiple fields and receive it in my mutation as a param. But it throws Object of type proxy is not JSON serializable on passing it as a JSONField parameter for object creation.

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via
    a github repo, https://repl.it or similar.
    I have the following Django model with a JSONField inside:

from django_jsonfield_backport import models as mysql


class RaceReport(TimeStampedModel):
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='race_reports')
    parameters = mysql.JSONField(blank=True, default=dict)

Then, there's a custom InputObjectType which looks like this:

class ParametersInput(graphene.InputObjectType):
    start_point = BigInteger(required=True)
    end_point = BigInteger(required=True)
    data_type = DataType()

I am using the above input type inside the following Mutation:

class CreateRaceReport(graphene.Mutation):
    class Arguments:
        parameters = ParametersInput(required=True)

    def mutate(_root, info, parameters):  # noqa: N805
        race_report = RaceReport.objects.create(user=info.context.user, parameters=parameters) # origin of the error
        return CreateRaceReport(race_report=race_report)
  • What is the expected behavior?
    The InputObjectType should be resolved after we access its attributes or useparameters.__dict__ but it stays lazy and causes the JSON encoding errors.

  • What is the motivation / use case for changing the behavior?
    Better compatibility with JSONField.

  • Please tell us about your environment:

    • Version: 2.1.8
    • Platform: MacOS 13.0.1
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow)

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

No branches or pull requests

1 participant