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.

SerializerMutation creates excess types for fields with same serializer class

See original GitHub issue

I use SerializerMutation to create/update objects:

from graphene_django.rest_framework.mutation import SerializerMutation

class ShipmentMutation(SerializerMutation):
    class Meta:
        serializer_class = ShipmentSerializer

Here is ShipmentSerializer:

from rest_framework import serializers

from logistics.models import City
from logistics.serializers import CitySerializer

from .models import Shipment


class ShipmentSerializer(serializers.ModelSerializer):
    owner = serializers.PrimaryKeyRelatedField(read_only=True)
    origin = CitySerializer(read_only=True)
    destination = CitySerializer(read_only=True)

    class Meta:
        model = Shipment
        exclude = ('created_at', 'updated_at', )

…and CitySerializer:

class CitySerializer(serializers.ModelSerializer):
    class Meta:
        model = City
        fields = ('id', 'name', )
        read_only_fields = ('id', 'name', )

So there is ttwo similar fields serialized by CitySerializer: origin and destination and while creating appropriate types for it raises an error:

AssertionError: Found different types with the same name in the schema: CitySerializerInput, CitySerializerInput.
Full trace
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7fb41bb8b620>
Traceback (most recent call last):
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/channels/management/commands/runserver.py", line 55, in inner_run
    self.check(display_num_errors=True)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/django/core/management/base.py", line 364, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/django/core/management/base.py", line 351, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/django/core/checks/registry.py", line 73, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
    all_namespaces = _load_all_namespaces(resolver)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
    url_patterns = getattr(resolver, 'url_patterns', [])
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/django/utils/functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 540, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/django/utils/functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 533, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/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 "/someusernamehere/donnyyy/Workspace/m100/m100-backend/m100/urls.py", line 21, in <module>
    from main.views import graphql_view
  File "/someusernamehere/donnyyy/Workspace/m100/m100-backend/main/views.py", line 100, in <module>
    '.')[:-1])), settings.GRAPHENE['SCHEMA'].split('.')[-1])
  File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/someusernamehere/donnyyy/Workspace/m100/m100-backend/main/schema.py", line 75, in <module>
    + car_types
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphene/types/schema.py", line 62, in __init__
    self.build_typemap()
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphene/types/schema.py", line 126, in build_typemap
    initial_types, auto_camelcase=self.auto_camelcase, schema=self
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphene/types/typemap.py", line 80, in __init__
    super(TypeMap, self).__init__(types)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphql/type/typemap.py", line 28,in __init__
    self.update(reduce(self.reducer, types, OrderedDict()))  # type: ignore
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphene/types/typemap.py", line 88, in reducer
    return self.graphene_reducer(map, type)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphene/types/typemap.py", line 117, in graphene_reducer
    return GraphQLTypeMap.reducer(map, internal_type)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphql/type/typemap.py", line 106, in reducer
    field_map = type.fields
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphql/pyutils/cached_property.py", line 22, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphql/type/definition.py", line 221, in fields
    return define_field_map(self, self._fields)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphql/type/definition.py", line 235, in define_field_map
    field_map = field_map()
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphene/types/typemap.py", line 286, in construct_fields_for_type
    map = self.reducer(map, arg.type)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphene/types/typemap.py", line 88, in reducer
    return self.graphene_reducer(map, type)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphene/types/typemap.py", line 93, in graphene_reducer
    return self.reducer(map, type.of_type)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphene/types/typemap.py", line 88, in reducer
    return self.graphene_reducer(map, type)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphene/types/typemap.py", line 117, in graphene_reducer
    return GraphQLTypeMap.reducer(map, internal_type)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphql/type/typemap.py", line 106, in reducer
    field_map = type.fields
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphql/pyutils/cached_property.py", line 22, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphql/type/definition.py", line 655, in fields
    return self._define_field_map()
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphql/type/definition.py", line 660, in _define_field_map
    fields = self._fields()
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphene/types/typemap.py", line 274, in construct_fields_for_type
    map = self.reducer(map, field.type)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphene/types/typemap.py", line 88, in reducer
    return self.graphene_reducer(map, type)
  File "/home/someusernamehere/.local/lib/python3.6/site-packages/graphene/types/typemap.py", line 99, in graphene_reducer
    ).format(_type.graphene_type, type)
AssertionError: Found different types with the same name in the schema: CitySerializerInput, CitySerializerInput.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:5

github_iconTop GitHub Comments

1reaction
Shehab-Muhammadcommented, Jul 7, 2019

We still facing same error

0reactions
stale[bot]commented, Jun 11, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mutations - Graphene-Python
Graphene-Django comes with mutation classes that will convert the fields ... You can create a Mutation based on a serializer by using the...
Read more >
Django rest framework, use different serializers in the same ...
This method is used in your model mixins to retrieve the proper Serializer class. Note that there is also a get_serializer method which...
Read more >
Django + Graphene: From REST to GraphQL - FullStack Labs
Field makes sure to enable extra fields in the schema. ... import SerializerMutation from .types import PlayerType from .models import Player from ...
Read more >
graphene-django-extras - PyPI
This library add some extra funcionalities to graphene-django to facilitate ... tuple or list class UserModelType(DjangoSerializerType): """ With this type ...
Read more >
Graphene Documentation - Read the Docs
To create GraphQL types for each of our Django models, ... After we've done that, we will list those types as fields in...
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