Default_value option in Arguments inside Mutation is not working as expected
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Inizia con le chiamate ripetute a schema.execute nella riproduzione fornita di test_mutation e traccia il modo in cui AnimalFarm Arguments default_value viene passato a mutate. Verifica che un argomento animals omesso riceva una nuova lista vuota a ogni richiesta e aggiungi un test di regressione che copra entrambe le esecuzioni.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi,
- What is the current behavior?
When I am working with the following set up of graphene Mutation:
class AnimalFarm(graphene.Mutation):
class Arguments:
animals = graphene.List(graphene.String, default_value=[])
output = graphene.List(graphene.String)
def mutate(root, info, **filters):
import pdb; pdb.set_trace()
animals_mio = filters["animals"]
animals_mio.append('duck')
return animals_mio
class Mutation(graphene.ObjectType):
animal_farm = AnimalFarm.Field()
where you can see that I am declaring a Mutation that have and argument called "animals" which type is "graphene.List(graphene.String, default_value=[])", that means if I dont pass this argument in the mutation, graphene automatically filled this argument ("animals") with an empty list.
At this point all works perfect, but when I try the following steps, I reckon that could be a little bug in to reset the old value of "animals" argument.
- Step 1: Install the latest version of graphene, in a linux OS, in my case is Ubuntu 22.04.3 LTS:
pip install "graphene>=3.1"
- Step 2: Copy this code in a file with extension ".py", for example:
nano cool_file_name.py
- Step 3: Copy this code to have the example, where you can this bug:
import graphene
class Query(graphene.ObjectType):
nothing = graphene.String()
def resolve_nothing(root, info):
return "empty"
class AnimalFarm(graphene.Mutation):
class Arguments:
animals = graphene.List(graphene.String, default_value=[])
output = graphene.List(graphene.String)
def mutate(root, info, **filters):
import pdb; pdb.set_trace()
animals_local = filters["animals"]
animals_local.append('duck')
return animals_local
class Mutation(graphene.ObjectType):
animal_farm = AnimalFarm.Field()
schema = graphene.Schema(query=Query, mutation=Mutation)
mutation = """
mutation addAnimals{
animalFarm {
output
}
}
"""
def test_mutation():
# First request
result = schema.execute(mutation)
print(result)
# Second request, in this request it is the problem !!!
result = schema.execute(mutation)
print(result)
test_mutation()
- Step 4: Then save the changes and launch the file:
python3 cool_file_name.py
-
Step 5: Execute "n" + Enter, to check this steps that works as expected in the first request, where we can see that both variables:
animals_local
filters["animals"]
are equal as an empty list, as you can see in this image:
Now if we add a value to the variable "aniamls_local" we also see that works perfect:
-
Step 6: The bug appear in the second request, where we do same steps that in the Step 5, but in this second request if we check the value of varieble filters["animals"] we can see that its default value is the old value of the previous request, where we added "duck" word to "animals" list argument:
-
What is the expected behavior?
The expected behavior is that if I launch multiple request of this mutation and I dont pass any value for "animals" argument, the default_value must be what I declare in set up type (an empty list).
So graphene have to reset correctly the default_value and not persist old values. -
Please tell us about your environment:
- Version: graphene>=3.1
- Platform: Ubuntu 22.04.3 LTS
- Lingua principale
- Python
- Stelle
- 8.2k
- Fork
- 818
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di graphql-python/graphene
-
Tutorial mistakes Aperta🐛 bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
graphql-python/graphene#1389 · 5 commenti · 2 reazioni ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 68/100
graphql-python/graphene#1606 ·
-
Python 3.14 support Aperta✨ enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 38/100
graphql-python/graphene#1601 · 2 commenti ·
-
✨ enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
graphql-python/graphene#1600 ·
-
🐛 bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 55/100
graphql-python/graphene#1593 ·
Tutte le issue di graphql-python/graphene
Issue simili
-
bug confirmed issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
open-webui/open-webui#30750 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
OpenwaterHealth/openmotion-bloodflow-app#604 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
good first issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100