v0.342.0 rejects inherited fields that would lose their permission classes
Strawberry now raises at schema build time in two cases where a type used to be published with an inherited field that had lost its permission classes or extensions. The schema printed the same SDL as before, so nothing showed that the field was no longer guarded on that type.
Plain annotations overriding guarded fields
Re-declaring an inherited field with a plain annotation now raises
GuardedFieldOverrideError when the inherited field has permission classes or
extensions:
@strawberry.interfaceclass Account: email: str = strawberry.field(permission_classes=[IsStaff])
@strawberry.typeclass Company(Account): email: str # raises GuardedFieldOverrideError Override the field with strawberry.field() , passing the permission classes and
extensions it should have, or remove the annotation to inherit the field as it
is. The same applies to strawberry.auto fields on
strawberry.experimental.pydantic types. Re-declaring fields without permission
classes or extensions keeps working, including fields that only have directives,
like the ones of Apollo Federation. See
Guarded Field Override Error .
Fields inherited from two parents
A type inheriting a field from two parents that share an ancestor now raises
ConflictingInheritedFieldsError when only one of them re-declares the field,
whatever options the declarations have. This includes fields with a resolver:
@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 Declare the field on the type itself, with the options it should have:
@strawberry.typeclass Contract(Versioned, Restricted): body: str = strawberry.field(permission_classes=[IsStaff]) Types whose parents both re-declare the field, and types merging unrelated types
with merge_types , are not affected. See
Conflicting Inherited Fields Error .