Default_value option in Arguments inside Mutation is not working as expected
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 45/100
調査の方向性
提供された test_mutation の再現コードにある schema.execute の繰り返し呼び出しから始め、AnimalFarm Arguments default_value が mutate に渡される経路を追跡してください。省略された animals 引数がリクエストごとに新しい空のリストを受け取ることを確認し、両方の実行を対象とするリグレッションテストを追加してください。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- Python
- スター
- 8.2k
- フォーク
- 822
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
graphql-python/graphene のほかの issue
-
Tutorial mistakesオープン🐛 bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
graphql-python/graphene#1389 · コメント 5 件 · リアクション 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
graphql-python/graphene#1606 ·
-
Python 3.14 supportオープン✨ enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 38/100
graphql-python/graphene#1601 · コメント 2 件 ·
-
✨ enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
graphql-python/graphene#1600 ·
-
Inaccurate Float-to-Decimal Conversion in `parse_value` of `Decimal` `Scalar`対応中かも @mak626 が 608 日前に担当しました。 オープン🐛 bug
難易度 2/5 1〜3時間 初心者へのやさしさ 55/100
graphql-python/graphene#1593 ·
graphql-python/graphene の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
vllm-project/vllm#61131 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
kubernetes-client/python#2735 ·
メンテナーはふだん 1 日以内に返信
-
desktop help wanted test
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
docs pydanty:is-working
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
pydantic/pydantic-ai#10113 ·
メンテナーはふだん 1 日以内に返信
-
Tutorial unit test leaks sample data into tutorial doctest対応中かも @Gambit-Checkmate が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100