{"record":{"id":"24be861266967db6","repo":"makeplane/plane","slug":"please-provide-the-email-of-the-admin","errorCode":null,"errorMessage":"Please provide the email of the admin.","messagePattern":"Please provide the email of the admin\\.","errorType":"exception","errorClass":"CommandError","httpStatus":null,"severity":"error","filePath":"apps/api/plane/db/management/commands/create_instance_admin.py","lineNumber":24,"sourceCode":"from django.core.management.base import BaseCommand, CommandError\n\n# Module imports\nfrom plane.license.models import Instance, InstanceAdmin\nfrom plane.db.models import User\n\n\nclass Command(BaseCommand):\n    help = \"Add a new instance admin\"\n\n    def add_arguments(self, parser):\n        # Positional argument\n        parser.add_argument(\"admin_email\", type=str, help=\"Instance Admin Email\")\n\n    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)","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/makeplane/plane/blob/1c8a60f858d8472aa56e29994ec1c7926da2c6ce/apps/api/plane/db/management/commands/create_instance_admin.py#L6-L42","documentation":"Raised by `create_instance_admin` when `options['admin_email']` is falsy (line 23). Because `admin_email` is declared as a required positional argument (line 18), argparse rejects a missing value before `handle()` runs, so this branch is effectively only reachable when the command is invoked programmatically (e.g. `call_command`) with a falsy value. It is a defensive guard, not a normal CLI path.","triggerScenarios":"Calling `call_command('create_instance_admin', admin_email=None)` or `admin_email=''` from Python code; otherwise argparse blocks invocation with the standard 'the following arguments are required' message.","commonSituations":"Custom orchestration scripts or tests that bypass argparse and pass an empty/None admin_email into `call_command`.","solutions":["Invoke via the CLI: `python manage.py create_instance_admin admin@example.com` so argparse enforces presence.","If calling programmatically, pass a non-empty string for `admin_email`.","Add a pre-check in your wrapper: `if not admin_email: raise ValueError(...)` before calling."],"exampleFix":"# before\ncall_command('create_instance_admin', admin_email='')\n# after\ncall_command('create_instance_admin', admin_email='admin@example.com')","handlingStrategy":"validation","validationCode":"import sys\nadmin_email = ''  # sourced from your script/env\nif not admin_email:\n    sys.exit('admin_email is required')\n# then: call_command('create_instance_admin', admin_email=admin_email)","typeGuard":"def is_non_empty_email(value) -> bool:\n    return isinstance(value, str) and bool(value.strip()) and '@' in value","tryCatchPattern":"from django.core.management import call_command\nfrom django.core.management.base import CommandError\ntry:\n    call_command('create_instance_admin', admin_email=admin_email)\nexcept CommandError as e:\n    # handle (note: argparse still rejects missing positional before this)\n    ...","preventionTips":["Invoke via CLI so argparse enforces the required positional.","Validate non-empty in any wrapper script before call_command."],"tags":["django","management-command","validation","argparse","plane"],"backgroundTag":null,"analyzedSha":"1c8a60f858d8472aa56e29994ec1c7926da2c6ce","analyzedAt":"2026-08-12T14:44:31.636Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}