Conflicting Inherited Fields Error

Description

This error is raised when a type inherits a field from parents that don’t override each other, and they declare it with different permission classes or extensions. For example, the following code will throw this error:

import strawberry
 
 
@strawberry.interface
class PublicProfile:
    email: str
 
 
@strawberry.interface
class Account:
    email: str = strawberry.field(permission_classes=[IsStaff])
 
 
@strawberry.type
class Company(PublicProfile, Account):  # raises ConflictingInheritedFieldsError
    pass

Which of the two fields Company gets depends on the order of its bases, so the field would be readable by anyone, or only by staff, depending on which parent is listed first. Strawberry doesn’t combine the permission classes of the parents, so the type has to say which ones the field has.

The same happens with types that share an ancestor, when only one of them re-declares the field:

@strawberry.interface
class Document:
    body: str
 
 
@strawberry.interface
class Versioned(Document):
    version: int
 
 
@strawberry.interface
class Restricted(Document):
    body: str = strawberry.field(permission_classes=[IsStaff])
 
 
@strawberry.type
class Contract(Versioned, Restricted):  # raises ConflictingInheritedFieldsError
    pass

Python's method resolution order puts Restricted before Document , but dataclasses copy the whole field table of each base, so Contract would get the body that Versioned inherits from Document , without the permission classes.

And with merge_types , when the merged types have a field with the same name and different permission classes or extensions.

Permission classes are compared as classes. Two fields that each declare their own extensions always count as different, even when the extensions are the same, while a field inherited through two parents counts once. Fields whose parents only differ in other options, like their description, directives or resolver, don’t raise: the type gets the one dataclasses pick.

How to fix this error

Declare the field on the type itself, passing the permission classes and extensions it should have:

@strawberry.type
class Company(PublicProfile, Account):
    email: str = strawberry.field(permission_classes=[IsStaff])

An override that doesn't pass them would inherit them, so it raises the same error. To publish the field without them on purpose, pass empty lists:

@strawberry.type
class Company(PublicProfile, Account):
    email: str = strawberry.field(permission_classes=[], extensions=[])
Edit this page on GitHub