{"record":{"id":"f87ce2e617e07339","repo":"HumanSignal/label-studio","slug":"project-with-the-same-name-already-exists-title","errorCode":null,"errorMessage":"Project with the same name already exists: {title}","messagePattern":"Project with the same name already exists: (.+?)","errorType":"exception","errorClass":"ProjectExistException","httpStatus":null,"severity":"error","filePath":"label_studio/projects/api.py","lineNumber":220,"sourceCode":"\n    def get_serializer(self, *args, **kwargs):\n        sparse_fields = self.get_sparse_fields()\n        if self.request.method == 'GET' and sparse_fields is not None:\n            fields_param = settings.REST_FLEX_FIELDS.get('FIELDS_PARAM', 'fields')\n            kwargs[fields_param] = sparse_fields\n        return super().get_serializer(*args, **kwargs)\n\n    def get_serializer_context(self):\n        context = super(ProjectListAPI, self).get_serializer_context()\n        context['created_by'] = self.request.user\n        return context\n\n    def perform_create(self, ser):\n        try:\n            ser.save(organization=self.request.user.active_organization)\n        except IntegrityError as e:\n            if str(e) == 'UNIQUE constraint failed: project.title, project.created_by_id':\n                raise ProjectExistException(\n                    'Project with the same name already exists: {}'.format(ser.validated_data.get('title', ''))\n                )\n            raise LabelStudioDatabaseException('Database error during project creation. Try again.')\n\n    def get(self, request, *args, **kwargs):\n        return super(ProjectListAPI, self).get(request, *args, **kwargs)\n\n    @api_webhook(WebhookAction.PROJECT_CREATED)\n    def post(self, request, *args, **kwargs):\n        return super(ProjectListAPI, self).post(request, *args, **kwargs)\n\n\n@method_decorator(\n    name='get',\n    decorator=extend_schema(\n        tags=['Projects'],\n        summary=\"List projects' counts\",\n        parameters=[","sourceCodeStart":202,"sourceCodeEnd":238,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/projects/api.py#L202-L238","documentation":"Projects enforce a unique (title, created_by_id) constraint. When creating a project whose title duplicates one of the same user's projects, the IntegrityError is translated to ProjectExistException with this message. It is an application-level duplicate-name error, not a DB failure.","triggerScenarios":"POST /api/projects with a title identical to an existing project owned by the same user (exact string match; DB UNIQUE constraint on project.title + project.created_by_id).","commonSituations":"Re-running an import/setup script twice; copying an existing project's title in the UI; automated test fixtures creating the same-named project; case differences are NOT distinguished beyond DB collation.","solutions":["Rename the new project to a unique title","List existing projects (GET /api/projects) and reuse or delete the duplicate","Check str(err) for the exact UNIQUE constraint string before assuming it's the name clash","Wrap creation in a check: Project.objects.filter(title=title, created_by=user).exists()"],"exampleFix":"// before\naxios.post('/api/projects', { title: 'My Project' }) // 400 ProjectExistException\n// after\nconst { data: existing } = await axios.get('/api/projects?title=My Project');\nif (existing.results.length === 0) {\n  await axios.post('/api/projects', { title: 'My Project' });\n} else {\n  title = 'My Project 2'; // or reuse existing project\n}","handlingStrategy":"validation","validationCode":"if Project.objects.filter(title=title, created_by=user).exists():\n    raise ValueError(f'Project with the same name already exists: {title}')","typeGuard":null,"tryCatchPattern":"try:\n    project = await axios.post('/api/projects', { title });\ncatch (e) {\n  if (e.response?.data?.includes?.('already exists')) {\n    // reuse or rename\n  } else throw e;\n}","preventionTips":["Check for existing projects by title before POST","Add timestamps/suffixes to scripted project names","Make idempotent scripts: look up before create","Educate users the name must be unique per owner"],"tags":["django","rest","duplicate","unique-constraint"],"backgroundTag":"duplicate-resource-name","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}