Support base class relations and reverse for proxy models by TomsOverBaghdad · Pull Request #1380 · graphql-python/graphene-django (original) (raw)

I believe this PR may have introduced a "regression" when combined with django-polymorphic.

In Django Polymorphic, the parent type exposes accessors to the derived types, which are now picked up by the updated get_reverse_fields logic and added to the derived type fields.

Here's an example of what I mean. Assuming the following models:

from polymorphic.models import PolymorphicModel

class Vehicle(PolymorphicModel): id = UUIDField()

class Car(Vehicle): ...

class Truck(Vehicle): ...

now the Car and Truck types will expose car and truck fields (that came from the parent). And these fields don't have associated resolvers, so the following GraphQL query will raise an Exception:

query { cars { id # The presence of these two fields makes no logical sense, and resolving them raises car { id } truck { id } } }

I suppose this is not really Graphene Django's concern to ensure downstream compatibility, but since Django Polymorphic is a quite popular library, I believe this is worth reporting here?

A quick workaround is to add these duplicated fields to the exclude lists of the derived types:

class CarType(DjangoObjectType): class Meta: exclude = ["car", "truck"]

but this is not most elegant.