AttributeError: object of type 'user' has no attribute 'name'


Freddie Martinez Garcia

I am new to graphene and I have this:

from django.contrib.auth.models import User

class UserType(DjangoObjectType):
    class Meta:
        model = User

Basically, using Django's User class gives me this error because before using the django User class I used my own User definition and it worked. Why does using the User class from the django authentication framework give me the error mentioned in the title:

File "/usr/local/lib/python3.6/site-packages/graphql/type/typemap.py" line 60 in reducer if type.name in map: AttributeError: type object 'User' has no property 'name''

Am I missing something?

greeting

PD: I'm using Django 2.0.4

Traceback

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x107c49e18>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 120, in inner_run
    self.check(display_num_errors=True)
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 364, in check
    include_deployment_checks=include_deployment_checks,
  File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 351, in _run_checks
    return checks.run_checks(**kwargs)
  File "/usr/local/lib/python3.6/site-packages/django/core/checks/registry.py", line 73, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/usr/local/lib/python3.6/site-packages/django/core/checks/urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "/usr/local/lib/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver
    return check_method()
  File "/usr/local/lib/python3.6/site-packages/django/urls/resolvers.py", line 397, in check
    for pattern in self.url_patterns:
  File "/usr/local/lib/python3.6/site-packages/django/utils/functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python3.6/site-packages/django/urls/resolvers.py", line 536, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/usr/local/lib/python3.6/site-packages/django/utils/functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python3.6/site-packages/django/urls/resolvers.py", line 529, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/freddy/PycharmProjects/DYD/DYD/urls.py", line 19, in <module>
    from dyd_server.graphql import schema
  File "/Users/freddy/PycharmProjects/DYD/dyd_server/graphql/__init__.py", line 10, in <module>
    schema = graphene.Schema(query=RootQuery, mutation=Mutations)
  File "/usr/local/lib/python3.6/site-packages/graphene/types/schema.py", line 57, in __init__
    self.build_typemap()
  File "/usr/local/lib/python3.6/site-packages/graphene/types/schema.py", line 123, in build_typemap
    schema=self
  File "/usr/local/lib/python3.6/site-packages/graphene/types/typemap.py", line 69, in __init__
    super(TypeMap, self).__init__(types)
  File "/usr/local/lib/python3.6/site-packages/graphql/type/typemap.py", line 16, in __init__
    self.update(reduce(self.reducer, types, OrderedDict()))
  File "/usr/local/lib/python3.6/site-packages/graphene/types/typemap.py", line 77, in reducer
    return self.graphene_reducer(map, type)
  File "/usr/local/lib/python3.6/site-packages/graphene/types/typemap.py", line 107, in graphene_reducer
    return GraphQLTypeMap.reducer(map, internal_type)
  File "/usr/local/lib/python3.6/site-packages/graphql/type/typemap.py", line 80, in reducer
    field_map = type.fields
  File "/usr/local/lib/python3.6/site-packages/graphql/pyutils/cached_property.py", line 16, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/usr/local/lib/python3.6/site-packages/graphql/type/definition.py", line 180, in fields
    return define_field_map(self, self._fields)
  File "/usr/local/lib/python3.6/site-packages/graphql/type/definition.py", line 189, in define_field_map
    field_map = field_map()
  File "/usr/local/lib/python3.6/site-packages/graphene/types/typemap.py", line 250, in construct_fields_for_type
    map = self.reducer(map, field.type)
  File "/usr/local/lib/python3.6/site-packages/graphene/types/typemap.py", line 77, in reducer
    return self.graphene_reducer(map, type)
  File "/usr/local/lib/python3.6/site-packages/graphene/types/typemap.py", line 107, in graphene_reducer
    return GraphQLTypeMap.reducer(map, internal_type)
  File "/usr/local/lib/python3.6/site-packages/graphql/type/typemap.py", line 80, in reducer
    field_map = type.fields
  File "/usr/local/lib/python3.6/site-packages/graphql/pyutils/cached_property.py", line 16, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/usr/local/lib/python3.6/site-packages/graphql/type/definition.py", line 180, in fields
    return define_field_map(self, self._fields)
  File "/usr/local/lib/python3.6/site-packages/graphql/type/definition.py", line 189, in define_field_map
    field_map = field_map()
  File "/usr/local/lib/python3.6/site-packages/graphene/types/typemap.py", line 250, in construct_fields_for_type
    map = self.reducer(map, field.type)
  File "/usr/local/lib/python3.6/site-packages/graphene/types/typemap.py", line 78, in reducer
    return GraphQLTypeMap.reducer(map, type)
  File "/usr/local/lib/python3.6/site-packages/graphql/type/typemap.py", line 60, in reducer
    if type.name in map:
AttributeError: type object 'User' has no attribute 'name'
Mark Krellian

This error occurs when Django model classes are accidentally used in code instead of graphene type classes. For example, make sure your query is something like

user = graphene.Field(UserType)

replace

user = graphene.Field(User)

Related


AttributeError: object of type 'user' has no attribute 'name'

Freddie Martinez Garcia I am new to graphene and I have this: from django.contrib.auth.models import User class UserType(DjangoObjectType): class Meta: model = User Basically, using Django's User class gives me this error because before using the

AttributeError: object of type 'user' has no attribute 'name'

Freddie Martinez Garcia I am new to graphene and I have this: from django.contrib.auth.models import User class UserType(DjangoObjectType): class Meta: model = User Basically, using Django's User class gives me this error because before using the

AttributeError: type object 'user' has no attribute 'query'

Mark Herbert I have a large database, populated with sqlalchemy (original database - not flask-SQLAlachemy). I'm trying to add flask-security to a website, I realize it relies on flask-SQLAlachemy (not the original), but flask-SQLAlchemy can work with me (just

AttributeError: type object has no attribute

Jim Beam This is a valid multilevel inheritance program. When I run it, it says "AttributeError: object of type 'starts' has no attribute 'math'". I checked the class associations and they inherit. I'm a beginner so it will help me a lot going forward. class s

AttributeError: type object has no attribute

Jim Beam This is a valid multilevel inheritance program. When I run it, it says "AttributeError: object of type 'starts' has no attribute 'math'". I checked the class associations and they inherit. I'm a beginner so it will help me a lot going forward. class s

AttributeError: type object has no attribute

Jim Beam This is a valid multilevel inheritance program. When I run it, it says "AttributeError: object of type 'starts' has no attribute 'math'". I checked the class associations and they inherit. I'm a beginner so it will help me a lot going forward. class s

AttributeError: type object has no attribute

Jim Beam This is a valid multilevel inheritance program. When I run it, it says "AttributeError: object of type 'starts' has no attribute 'math'". I checked the class associations and they inherit. I'm a beginner so it will help me a lot going forward. class s

AttributeError: 'model' object has no attribute 'name'

Vatsal Aggarwal: I'm new to this and when I got this error I was Kerastrying to build a text-classification CNNmodel using Python 3.6: AttributeError: 'Model' object has no attribute 'name' Here is the code I wrote: print("\nCreating Model...") x1 = Input(sha

AttributeError: 'Doctype' object has no attribute 'name'

waibjavin I django-htmlminuse to minify HTML. But AttributeError: 'Doctype' object has no attribute 'name'on my production server. But in my development environment everything works fine. Here is the full traceback: {'levelname': ERROR,'time':24/Jan/2015 16:59

AttributeError: 'Doctype' object has no attribute 'name'

waibjavin I django-htmlminuse to minify HTML. But AttributeError: 'Doctype' object has no attribute 'name'on my production server. But in my development environment everything works fine. Here is the full traceback: {'levelname': ERROR,'time':24/Jan/2015 16:59

AttributeError: 'str' object has no attribute 'name' PySpark

exchange I created the list and tried to assign it to StructType() but got the error: AttributeError: 'str' object has no attribute 'name' my code: from pyspark.sql import SparkSession import logging from pyspark.sql.types import * from pyspark.sql.functions

AttributeError: 'model' object has no attribute 'name'

Vatsal Aggarwal: I'm new to this and when I got this error I was Kerastrying to build a text-classification CNNmodel using Python 3.6: AttributeError: 'Model' object has no attribute 'name' Here is the code I wrote: print("\nCreating Model...") x1 = Input(sha

AttributeError: 'Doctype' object has no attribute 'name'

waibjavin I django-htmlminuse to minify HTML. But AttributeError: 'Doctype' object has no attribute 'name'on my production server. But in my development environment everything works fine. Here is the full traceback: {'levelname': ERROR,'time':24/Jan/2015 16:59

AttributeError: 'str' object has no attribute 'name'

beginner class System: def __init__(self,code,name,price): self.name = name self.price = price self.code = code def __str__(self): return 'Code: ' + self.code + '\tName: ' self.name + \'tPrice: ' + self.price def

AttributeError: 'str' object has no attribute '__name__'

Andreas hates censorship What is causing this error? Is it not possible to comment out such lines in internal code? for i in (Class_1, """Class_2, Class_3"""): name = i.__name__ Class_1, Class_2and Class_3for the class declared before the code above. Erro

AttributeError on /notify/ 'user' object has no attribute 'get'

Ahmed Yasin When I create the user object, in views.py. It shows me and the error AttributeError at /notify/ , 'User' object has no attribute 'get', how can I fix it. from django.contrib.auth.models import User class NotifyView(TemplateView): template_nam

AttributeError: 'user' object has no attribute 'is_admin'

strontium I customized the user model by extending AbstractBaseUser which accepts only as email id. Here is the model: class User(AbstractBaseUser, PermissionsMixin): email = models.EmailField('email address', unique=True) first_name = models.CharField

AttributeError: 'WSGIRequest' object has no attribute 'user'

Zhiyuan Leng I am running Django code and I am getting this error AttributeError: 'WSGIRequest' object has no attribute 'user' My Django version is 1.8.2 and this is my middleware class setting.py MIDDLEWARE_CLASSES = ( 'khxia.middlewares.PeeweeConnectionMid

AttributeError on /notify/ 'user' object has no attribute 'get'

Ahmed Yasin When I create the user object, in views.py. It shows me and the error AttributeError at /notify/ , 'User' object has no attribute 'get', how can I fix it. from django.contrib.auth.models import User class NotifyView(TemplateView): template_nam

AttributeError: 'WSGIRequest' object has no attribute 'user'

Zhiyuan Leng I am running Django code and I am getting this error AttributeError: 'WSGIRequest' object has no attribute 'user' My Django version is 1.8.2 and this is my middleware class setting.py MIDDLEWARE_CLASSES = ( 'khxia.middlewares.PeeweeConnectionMid

AttributeError: 'WSGIRequest' object has no attribute 'user'

Zhiyuan Leng I am running Django code and I am getting this error AttributeError: 'WSGIRequest' object has no attribute 'user' My Django version is 1.8.2 and this is my middleware class setting.py MIDDLEWARE_CLASSES = ( 'khxia.middlewares.PeeweeConnectionMid

AttributeError: 'WSGIRequest' object has no attribute 'user'

Zhiyuan Leng I am running Django code and I am getting this error AttributeError: 'WSGIRequest' object has no attribute 'user' My Django version is 1.8.2 and this is my middleware class setting.py MIDDLEWARE_CLASSES = ( 'khxia.middlewares.PeeweeConnectionMid

AttributeError: 'WSGIRequest' object has no attribute 'user'

Zhiyuan Leng I am running Django code and I am getting this error AttributeError: 'WSGIRequest' object has no attribute 'user' My Django version is 1.8.2 and this is my middleware class setting.py MIDDLEWARE_CLASSES = ( 'khxia.middlewares.PeeweeConnectionMid