question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

When creating Mutation I get: AttributeError: 'Options' object has no attribute 'name'

See original GitHub issue

Created simple Queries with no issues. No trying to create a Mutation and getting this error.

  File "C:\Program Files\Python36\lib\site-packages\graphene\types\typemap.py",
line 236, in construct_fields_for_type
    field_type = self.get_field_type(map, field.type)
  File "C:\Program Files\Python36\lib\site-packages\graphene\types\typemap.py",
line 295, in get_field_type
    return map.get(type._meta.name)
AttributeError: 'Options' object has no attribute 'name'

This is the code

class AddProduct(graphene.Mutation):
    class Input:
        name = String(required=True)

    product = Field(Product)
    org = Field(Org)

    @classmethod
    def mutate(cls, input, context, info):
        product_name = input.get('product_name')
        org = Org.objects.first();
        desc = "description whatever...."
        product = Product(name = product_name, org = org, description = desc)

        return AddProduct(product = product)

class Mutation(ObjectType):
    add_product = AddProduct.Field()

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

21reactions
colanconnoncommented, May 2, 2017

Without knowing more about your code, I assume you are using Product and Org from your models and not making them into graphql types. If you make product and Org into graphene types this should work.

3reactions
picturedotscommented, May 19, 2017

Having also just stumbled on this just following the mutation example in the docs ( http://docs.graphene-python.org/en/latest/types/mutations/) , it seems that the exception message could be a bit more helpful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AttributeError: type object 'User' has no attribute 'name'
This is a cryptic error that happens when Django Model classes are accidentally used in code instead of graphene Type classes.
Read more >
AttributeError: 'Options' object has no attribute 'name'
When creating Mutation I get : AttributeError: 'Options' object has no attribute 'name'
Read more >
unittest.mock — getting started — Python 3.11.1 documentation
AttributeError : object has no attribute 'old_method'. Using a specification also enables a smarter matching of calls made to the mock, regardless of...
Read more >
'int' object has no attribute 'choice' - appsloveworld.com
I am writing a python program and I get this error: Traceback (most recent call last): File "C:\Users\Joe\SkyDrive\Documents\Python Project\Python\Forest ...
Read more >
Configuring the Apollo Client cache - Apollo GraphQL Docs
To learn how to interact with cached data, see Reading and writing data to the cache. Initialization. Create an InMemoryCache object and provide...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found