{"record":{"id":"395e68a1f32db869","repo":"makeplane/plane","slug":"the-provided-email-is-already-an-instance-admin","errorCode":null,"errorMessage":"The provided email is already an instance admin.","messagePattern":"The provided email is already an instance admin\\.","errorType":"exception","errorClass":"CommandError","httpStatus":null,"severity":"warning","filePath":"apps/api/plane/db/management/commands/create_instance_admin.py","lineNumber":38,"sourceCode":"    def handle(self, *args, **options):\n        admin_email = options.get(\"admin_email\", False)\n\n        if not admin_email:\n            raise CommandError(\"Please provide the email of the admin.\")\n\n        user = User.objects.filter(email=admin_email).first()\n        if user is None:\n            raise CommandError(\"User with the provided email does not exist.\")\n\n        try:\n            # Get the instance\n            instance = Instance.objects.last()\n\n            # Get or create an instance admin\n            _, created = InstanceAdmin.objects.get_or_create(user=user, instance=instance, role=20)\n\n            if not created:\n                raise CommandError(\"The provided email is already an instance admin.\")\n\n            self.stdout.write(self.style.SUCCESS(\"Successfully created the admin\"))\n        except Exception as e:\n            print(e)\n            raise CommandError(\"Failed to create the instance admin.\")\n","sourceCodeStart":20,"sourceCodeEnd":44,"githubUrl":"https://github.com/makeplane/plane/blob/1c8a60f858d8472aa56e29994ec1c7926da2c6ce/apps/api/plane/db/management/commands/create_instance_admin.py#L20-L44","documentation":"Raised when `InstanceAdmin.objects.get_or_create(user=user, instance=instance, role=20)` returns `created=False` (lines 35-38), i.e. an `InstanceAdmin` row for that user already exists. IMPORTANT: this raise occurs inside the `try` block (line 30) whose `except Exception` (lines 41-43) catches it, prints it, and re-raises the GENERIC message 'Failed to create the instance admin.' (error 84). So the operator normally never sees this message — they see [84] instead. This masking is a latent bug.","triggerScenarios":"Running `create_instance_admin` for a user who is already an instance admin; the get_or_create finds the existing row and `created` is False.","commonSituations":"Re-running the command after a previous successful run; an admin was provisioned via setup scripts or the UI already.","solutions":["Recognize the user is already an admin — no action needed; this is not a real failure.","To list existing admins: `python manage.py shell -c \"from plane.license.models import InstanceAdmin; print([a.user.email for a in InstanceAdmin.objects.all()])\"`","Fix the masking bug by moving the `if not created` check outside the try, or by catching only specific DB exceptions instead of bare `Exception`."],"exampleFix":"# before (bug: [83] is swallowed and re-raised as [84])\ntry:\n    _, created = InstanceAdmin.objects.get_or_create(...)\n    if not created:\n        raise CommandError(\"The provided email is already an instance admin.\")\nexcept Exception as e:\n    print(e)\n    raise CommandError(\"Failed to create the instance admin.\")\n# after (move the idempotency check out of the try)\n_, created = InstanceAdmin.objects.get_or_create(user=user, instance=instance, role=20)\nif not created:\n    self.stdout.write(self.style.WARNING(\"Already an instance admin\"))\n    return","handlingStrategy":"try-catch","validationCode":"from plane.license.models import InstanceAdmin\nfrom plane.db.models import User\nalready = InstanceAdmin.objects.filter(user__email='admin@example.com').exists()\n# if already: skip the command; it is idempotent-but-noisy","typeGuard":"def is_already_instance_admin(email: str) -> bool:\n    from plane.license.models import InstanceAdmin\n    return InstanceAdmin.objects.filter(user__email=email).exists()","tryCatchPattern":"# WARNING: create_instance_admin masks [83] as [84] via its bare except.\n# Pre-check instead of relying on the message:\nfrom plane.license.models import InstanceAdmin\nif InstanceAdmin.objects.filter(user__email=email).exists():\n    print('already an admin; skipping')\nelse:\n    call_command('create_instance_admin', email)","preventionTips":["Pre-check InstanceAdmin membership before running (the command's error is masked).","Treat 'Failed to create the instance admin' as possibly meaning 'already an admin'.","Fix the masking bug by moving the idempotency check outside the try."],"tags":["django","management-command","idempotency","exception-masking","plane","bug"],"backgroundTag":null,"analyzedSha":"1c8a60f858d8472aa56e29994ec1c7926da2c6ce","analyzedAt":"2026-08-12T14:44:31.636Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}