v0.343.0 keeps the permission classes of overridden fields
Overrides keep the permission classes and extensions
A field declared with strawberry.field() , or with a resolver, that overrides
an inherited field now keeps the permission classes and extensions of the
inherited field, unless it passes its own. Before, the override replaced them
with its own options, so a field overridden only to change its description,
directives or resolver lost its permission classes, without any error:
@strawberry.interfaceclass Account: email: str = strawberry.field(permission_classes=[IsStaff])
@strawberry.typeclass Company(Account): # was readable by anyone, now only by staff email: str = strawberry.field(description="Billing email") This applies to strawberry.field() , strawberry.mutation() ,
strawberry.federation.field() , relay.connection() , relay.node() , and to
the fields of strawberry.pydantic and strawberry.experimental.pydantic
types. The extensions an override keeps are its parentโs own extensions ,
including ones that donโt check permissions, like formatting or caching
extensions.
Fields that are meant to be readable without the inherited permission classes
now need to say so, with permission_classes=[] , and extensions=[] for
extensions:
@strawberry.typeclass Company(Account): email: str = strawberry.field(permission_classes=[]) Passing extensions only replaces the extensions, and passing
permission_classes only replaces the permission classes, so
strawberry.field(permission_classes=[IsAdmin]) over a field whose guard is a
PermissionExtension in its extensions checks both.
An override that adds a resolver, or removes the one of the inherited field,
raises GuardedFieldOverrideError when the inherited field has its own
extensions, as they can depend on the resolver. Pass the extensions the field
should have. See
Guarded Field Override Error .
Plain annotations, like email: str , keep raising GuardedFieldOverrideError
when they override a field with permission classes or extensions. This now also
applies to strawberry.pydantic types, which used to drop them, including
fields declared with Annotated[..., strawberry.field(...)] on pydantic models
that arenโt decorated. strawberry.Private annotations can still override such
fields, which keeps the inherited field as it is. Input types are no longer
checked, as permission classes and extensions donโt do anything on input fields.
Fields inherited from parents that guard them differently
ConflictingInheritedFieldsError is now raised when a type inherits a field
from parents that donโt override each other and declare it with different
permission classes or extensions. This includes unrelated parents, and types
merged with merge_types , where the first type used to win:
@strawberry.interfaceclass PublicProfile: email: str
@strawberry.interfaceclass Account: email: str = strawberry.field(permission_classes=[IsStaff])
@strawberry.typeclass Company(PublicProfile, Account): # raises ConflictingInheritedFieldsError pass Declare the field on the type, passing the permission_classes and extensions
it should have. An override that doesnโt pass them raises too, as Strawberry
doesnโt combine the guards of the parents.
On the other hand, the error is no longer raised when the parents only differ in other options, like their resolver or directives. Diamonds like the one of 0.342.0โs breaking changes, where only one parent re-declares a field, still raise when the declarations have different permission classes or extensions. See Conflicting Inherited Fields Error .