makeplane/plane · error · CommandError

Failed to create the instance admin.

Error message

Failed to create the instance admin.

What it means

Generic catch-all raised by `create_instance_admin` from the bare `except Exception as e` (lines 41-43). It fires for ANY exception inside the try block — most commonly it MASKS the legitimate 'already an admin' case ([83]) because that CommandError is also an Exception and gets caught here. The original exception is only `print()`-ed to stdout, not surfaced in the CommandError message, making diagnosis hard.

Source

Thrown at apps/api/plane/db/management/commands/create_instance_admin.py:43

        user = User.objects.filter(email=admin_email).first()
        if user is None:
            raise CommandError("User with the provided email does not exist.")

        try:
            # Get the instance
            instance = Instance.objects.last()

            # Get or create an instance admin
            _, created = InstanceAdmin.objects.get_or_create(user=user, instance=instance, role=20)

            if not created:
                raise CommandError("The provided email is already an instance admin.")

            self.stdout.write(self.style.SUCCESS("Successfully created the admin"))
        except Exception as e:
            print(e)
            raise CommandError("Failed to create the instance admin.")

View on GitHub (pinned to 1c8a60f858)

Solutions

  1. Watch stdout for the `print(e)` output immediately before the error — it prints the real cause.
  2. If the user is already an admin, this error is expected; verify with `InstanceAdmin.objects.filter(user=...).exists()`.
  3. Refactor: narrow the except to `IntegrityError`/`DatabaseError` and move the `if not created` branch outside the try so [83] is reported accurately.
  4. Ensure an `Instance` record exists (run instance setup) before promoting admins.

Example fix

# before
except Exception as e:
    print(e)
    raise CommandError("Failed to create the instance admin.")
# after — surface the real cause and stop masking [83]
except (IntegrityError, DatabaseError) as e:
    raise CommandError(f"Failed to create the instance admin: {e}") from e
Defensive patterns

Strategy: try-catch

Validate before calling

# Pre-flight: instance must exist and user must NOT already be an admin
from plane.license.models import Instance, InstanceAdmin
assert Instance.objects.exists(), 'No Instance row; run instance setup first'
assert not InstanceAdmin.objects.filter(user__email=email).exists(), 'already admin'

Type guard

def instance_ready_for_admin(email: str) -> bool:
    from plane.license.models import Instance, InstanceAdmin
    return Instance.objects.exists() and not InstanceAdmin.objects.filter(user__email=email).exists()

Try / catch

# The real cause is print()-ed to stdout, not in the CommandError.
# Capture stdout to recover it, or pre-validate as above.
from io import StringIO
out = StringIO()
try:
    call_command('create_instance_admin', email, stdout=out)
except CommandError:
    print('real cause was printed to stdout:', out.getvalue())

Prevention

When it happens

Trigger: Any failure between lines 30-40: an existing InstanceAdmin (masks [83]); `Instance.objects.last()` returning None combined with a non-null instance constraint; DB integrity error; the `print(e)` line itself.

Common situations: Re-running on an already-admin user (most frequent); no `Instance` row exists yet (instance not set up); DB connectivity / constraint violations.

Related errors


AI-assisted analysis of makeplane/plane@1c8a60f858 (2026-08-12). Data as JSON: /api/errors/b8ee65a370c263dd. Report an issue: GitHub.