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.interfaceclass PublicProfile: email: str
@strawberry.interfaceclass Account: email: str = strawberry.field(permission_classes=[IsStaff])
@strawberry.typeclass 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.interfaceclass Document: body: str
@strawberry.interfaceclass Versioned(Document): version: int
@strawberry.interfaceclass Restricted(Document): body: str = strawberry.field(permission_classes=[IsStaff])
@strawberry.typeclass 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.typeclass 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.typeclass Company(PublicProfile, Account): email: str = strawberry.field(permission_classes=[], extensions=[])