graphql-python / graphene-django

Build powerful, efficient, and flexible GraphQL APIs with seamless Django integration.
http://docs.graphene-python.org/projects/django/en/latest/
MIT License
4.31k stars 770 forks source link

InputObjectType causing encoding issues with JSONField #1389

Open adilhussain540 opened 1 year ago

adilhussain540 commented 1 year ago

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

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 use`parameters.__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)
- https://stackoverflow.com/questions/75412492/graphene-inputobjecttype-causing-encoding-issues-with-jsonfield