Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Default_value option in Arguments inside Mutation is not working as expected

Open
#1,534 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
graphql, python
Domain
api, backend

Research direction

Start with the repeated schema.execute calls in the provided test_mutation reproduction and trace how the AnimalFarm Arguments default_value is passed into mutate. Confirm that an omitted animals argument receives a fresh empty list on each request, and add a regression test covering both executions.

Written by the indexing model from the issue text.

Description

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:
    image
    Now if we add a value to the variable "aniamls_local" we also see that works perfect:
    image

  • 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:
    image

  • 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
Dominant language
Python
Stars
8.2k
Forks
818
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from graphql-python/graphene

All issues in graphql-python/graphene

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.