graphql-python / graphql-python/graphene-django

Django ValidationError are serialized as string instead of error array

Open
#1,042 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
4.4k
Forks
760
PR merge metrics
No merged PRs in 30d

Description

* **What is the current behavior?**

Django ValidationError are serialized as string instead of error array.

```python
from django.core.exceptions import ValidationError

from graphene import ObjectType, Schema, Int

class Query(ObjectType):
test = Int()

def resolve_test(root, context, **kwargs):
raise ValidationError("error message")

schema = Schema(query=Query)
```
or [https://repl.it/repls/AffectionateObviousBookmark#cookbook/schema.py](https://repl.it/repls/AffectionateObviousBookmark#cookbook/schema.py)

For the following query:
```
query Test {
test
}
```

We got the following response:
```
{
"errors": [
{
"message": "['error message']",
"locations": [
{
"line": 33,
"column": 3
}
],
"path": [
"test"
]
}
],
"data": {
"test": null
}
}
```
Look at the message field ...

* **What is the expected behavior?**

```
{
"errors": [
{
"message": "error message",
"locations": [
{
"line": 33,
"column": 3
}
],
"path": [
"test"
]
}
],
"data": {
"test": null
}
}
```

* **Please tell us about your environment:**

- Version: django (^3.1), django-graphene (^2.13)
- Platform: linux

* **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.