graphql-python / graphql-python/graphene-django
InputObjectType causing encoding issues with JSONField
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 760
- PR merge metrics
- No merged PRs in 30d
Description
**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](https://stackoverflow.com/questions/48454398/typeerror-at-en-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 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
Contributor guide
Assessment
This issue has not been assessed yet.