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:

# Before
class IsAuthenticated(BasePermission):
def has_permission(self, source, info, **kwargs):
return info.context.user
# After
class 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.

Contributors:

Edit this page on GitHub