{"record":{"id":"e51936fdf56c8b8c","repo":"langfuse/langfuse","slug":"the-dataset-item-with-id-input-id-already-exist","errorCode":null,"errorMessage":"The dataset item with id ${input.id} already exists in a dataset other than ${datasetIdentifierForLog}","messagePattern":"The dataset item with id (.+?) already exists in a dataset other than (.+?)","errorType":"exception","errorClass":"LangfuseNotFoundError","httpStatus":404,"severity":"error","filePath":"web/src/features/datasets/server/publicDatasetService.ts","lineNumber":679,"sourceCode":"      ...transformDbDatasetItemDomainToAPIDatasetItem({\n        ...datasetItem,\n        datasetName: datasetItem.datasetName,\n        status: datasetItem.status ?? \"ACTIVE\",\n      }),\n      mediaReferences:\n        mediaReferences.get(datasetItemMediaReferenceKey(datasetItem)) ?? [],\n    };\n  } catch (error) {\n    if (error instanceof Prisma.PrismaClientKnownRequestError) {\n      if (error.code === \"P2025\") {\n        // this case happens when a dataset item was created for a different dataset.\n        // In the database, the uniqueness constraint is on (id, projectId) only.\n        // When this constraint is violated, the database will upsert based on (id, projectId, datasetId).\n        // If this record does not exist, the database will throw an error.\n        logger.warn(\n          `Failed to upsert dataset item. Dataset item ${input.id} already exists for a different dataset than ${datasetIdentifierForLog}`,\n        );\n        throw new LangfuseNotFoundError(\n          `The dataset item with id ${input.id} already exists in a dataset other than ${datasetIdentifierForLog}`,\n        );\n      }\n\n      if (error.code === \"P2002\") {\n        // Unique constraint violation on (id, projectId, validFrom).\n        // This can happen when concurrent requests try to update the same dataset item\n        // and create versions with the same timestamp.\n        logger.warn(\n          `Failed to upsert dataset item due to version conflict. Dataset item ${input.id} was modified concurrently.`,\n        );\n        throw new LangfuseConflictError(\n          `Dataset item ${input.id ?? \"new\"} was modified concurrently. Please retry the request.`,\n        );\n      }\n    }\n\n    throw error;","sourceCodeStart":661,"sourceCodeEnd":697,"githubUrl":"https://github.com/langfuse/langfuse/blob/59d92c7cf365150d10b753b5a0d1708902a2ed60/web/src/features/datasets/server/publicDatasetService.ts#L661-L697","documentation":"On upsert of a dataset item, the (id, projectId) uniqueness path fires when the supplied id already exists but is attached to a different dataset than the target. The service logs a warning and returns 404-style NotFoundError rather than moving the item between datasets.","triggerScenarios":"POST/PUT /api/public/dataset-items with an explicit id that already exists under another dataset in the same project (e.g. re-using an id from dataset A when writing to dataset B).","commonSituations":"Copy/sync scripts that reuse deterministic item ids across datasets; renaming a dataset and recreating it under a new name while re-importing items with the same ids.","solutions":["Use a dataset-scoped id scheme (e.g. `${datasetName}:${itemId}`) or omit id to let Langfuse generate one","Delete the item from the old dataset first if you intend to move it","Check which dataset owns the id: GET /api/public/dataset-items/:id"],"exampleFix":"// before\nawait datasetItems.create({ id: \"item-1\", datasetName: \"dataset-b\", ... });\n// after\nawait datasetItems.create({ id: \"dataset-b:item-1\", datasetName: \"dataset-b\", ... });","handlingStrategy":"validation","validationCode":"const existing = await client.fetch(`/api/public/dataset-items/${id}`);\nif (existing && existing.datasetName !== targetDataset) id = `${targetDataset}:${id}`;","typeGuard":null,"tryCatchPattern":"catch (e) { if (is404WithMessage(e, /already exists in a dataset other than/)) useNamespacedId(); else throw e; }","preventionTips":["Namespace deterministic item ids per dataset","Never assume ids are portable across datasets"],"tags":["dataset","unique-constraint","upsert","public-api"],"backgroundTag":"duplicate-resource-id","analyzedSha":"59d92c7cf365150d10b753b5a0d1708902a2ed60","analyzedAt":"2026-08-27T22:22:00.402Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}