# Buggy code
def create_permission_groups():
    super_users = User.objects.filter(is_superuser=True)
    if not super_users:
        super_users = create_staff_users(1, True)
    group = create_group("Full Access", Permission.objects.all(), super_users)
    yield f"Group: {group}"

    staff_users = create_staff_users()
    customer_support_codenames = [
        perm.codename
        for enum in [CheckoutPermissions, OrderPermissions, GiftcardPermissions]
        for perm in enum
    ]
    customer_support_codenames.append(AccountPermissions.MANAGE_USERS.codename)
    customer_support_permissions = Permission.objects.filter(
        codename__in=customer_support_codenames
    )
    group = create_group("Customer Support", customer_support_permissions, staff_users)
    yield f"Group: {group}"


# Traceback (ValueError)
{
"errors": [
{
"message": "'account.add_address' is not a valid PermissionEnum",
"locations": [
{
"line": 34,
"column": 3
}
],
"path": [
"permissionGroup",
"permissions"
],
"extensions": {
"exception": {
"code": "ValueError",
"stacktrace": [
"ValueError: 'account.add_address' is not a valid PermissionEnum",
"",
"During handling of the above exception, another exception occurred:",
"Traceback (most recent call last):",
"  File \"/usr/local/lib/python3.8/site-packages/promise/promise.py\", line 489, in _resolve_from_executor",
"    executor(resolve, reject)",
"  File \"/usr/local/lib/python3.8/site-packages/promise/promise.py\", line 756, in executor",
"    return resolve(f(*args, **kwargs))",
"  File \"/usr/local/lib/python3.8/site-packages/graphql/execution/middleware.py\", line 75, in make_it_promise",
"    return next(*args, **kwargs)",
"  File \"/app/saleor/graphql/account/types.py\", line 474, in resolve_permissions",
"    return format_permissions_for_display(permissions)",
"  File \"/app/saleor/graphql/utils.py\", line 175, in format_permissions_for_display",
"    PermissionDisplay(code=PermissionEnum.get(codename), name=permission.name)",
"  File \"/usr/local/lib/python3.8/site-packages/graphene/types/enum.py\", line 38, in get",
"    return cls._meta.enum(value)",
"  File \"/usr/local/lib/python3.8/enum.py\", line 304, in __call__",
"    return cls.__new__(cls, value)",
"  File \"/usr/local/lib/python3.8/enum.py\", line 595, in __new__",
"    raise exc",
"  File \"/usr/local/lib/python3.8/enum.py\", line 579, in __new__",
"    result = cls._missing_(value)",
"  File \"/usr/local/lib/python3.8/enum.py\", line 608, in _missing_",
"    raise ValueError(\"%r is not a valid %s\" % (value, cls.__name__))",
"ValueError: 'account.add_address' is not a valid PermissionEnum"
]
}
}
}
],
"data": {
"permissionGroup": {
"id": "R3JvdXA6MQ==",
"name": "Full Access",
"users": [
{
"id": "VXNlcjoyMQ==",
"firstName": "",
"lastName": "",
"__typename": "User",
"email": "admin@example.com",
"isActive": true,
"avatar": {
"url": "http://localhost:8000/media/user-avatars/avatar8.png",
"__typename": "Image"
}
}
],
"__typename": "Group",
"permissions": null
}
}
}

# Fixed code
def create_permission_groups():
    super_users = User.objects.filter(is_superuser=True)
    if not super_users:
        super_users = create_staff_users(1, True)
    group = create_group("Full Access", get_permissions(), super_users)
    yield f"Group: {group}"

    staff_users = create_staff_users()
    customer_support_codenames = [
        perm.codename
        for enum in [CheckoutPermissions, OrderPermissions, GiftcardPermissions]
        for perm in enum
    ]
    customer_support_codenames.append(AccountPermissions.MANAGE_USERS.codename)
    customer_support_permissions = Permission.objects.filter(
        codename__in=customer_support_codenames
    )
    group = create_group("Customer Support", customer_support_permissions, staff_users)
    yield f"Group: {group}"