v0.338.0 requires permissions to return a boolean
has_permission must now return True or False (or, for an asynchronous
permission, resolve to one). Previously Strawberry granted access for any truthy
value, which meant results it could not evaluate, such as the async generator
returned by an async def has_permission that uses yield , were treated as
granting access.
Any non-boolean result now raises PermissionReturnedNonBooleanError , and the
field resolves to an error. This is a programming error, so it is raised even
when the permission extension uses fail_silently=True .
Upgrading
Permissions that return a non-boolean value need to be updated to return a
boolean explicitly. Wrapping the old result in bool(...) keeps the exact same
access decisions:
# Beforeclass IsAuthenticated(BasePermission): def has_permission(self, source, info, **kwargs): return info.context.user
# Afterclass IsAuthenticated(BasePermission): def has_permission(self, source, info, **kwargs) -> bool: return bool(info.context.user) Permissions that already return True or False donβt need any change.