graphql-python / graphql-python/graphene-django

DjangoDebug needs context to be writable

Open
#1,470 4 comments 0 reactions 0 assignees View on GitHub
🐛bug
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?**
When trying to access http://localhost:8000/graphql with `DEBUG = True`, the GraphQL interface returns the following error and is unable to load the schema:

```
{
"errors": [
{
"message": "DjangoDebug need the context to be writable, context received: WSGIRequest.",
"locations": [
{
"line": 3,
"column": 7
}
],
"path": [
"__schema"
]
}
],
"data": null
}
```

* **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 (you can use this template as a starting point: https://repl.it/@jkimbo/Graphene-Django-Example).

Blank Django project, set DEBUG to True.
Schema settings used:
```
GRAPHENE = {
"SCHEMA": "coldplaysharks.schema.schema",
}
```

Relevant schema file
```
import graphene
from graphene_django import DjangoObjectType

from .models import Team

class TeamType(DjangoObjectType):
class Meta:
model = Team

class Query(graphene.ObjectType):
teams = graphene.List(TeamType)

def resolve_teams(root, info, **kwargs):
return Team.objects.all()

schema = graphene.Schema(query=Query)
```

Relevant models.py file for Team
```
class Team(models.Model):
"""Holds all information related to the different teams in the club."""

name = models.CharField(max_length=250)
slug = models.SlugField(unique=True)
logo = models.ImageField(upload_to="team/logo/")
menu_active = models.BooleanField("Show in menu?", default=True, help_text="If activated this team will be shown under the 'Teams' menu option")
menu_weight = models.IntegerField(default=0, help_text="Teams in the menu will be ordered from heavy to lightest, with the lighter ones floating to the top")

created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)

def __str__(self):
return self.name
```

* **What is the expected behavior?**
I would expect to be able to query the schema using the GraphQL browser

* **What is the motivation / use case for changing the behavior?**
It's not working currently

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

- Version: 3.1.5 (Django version 4.2.6)
- Platform: Windows 11

* **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.