langgenius/dify · error · DatasetNameDuplicateError
dataset_name_duplicate
dataset_name_duplicate
Error message
The dataset name already exists. Please modify your dataset name.
What it means
Raised when creating an external-knowledge API template whose name already exists in the tenant. The service throws services.errors.dataset.DatasetNameDuplicateError, which the controller re-raises as the HTTP DatasetNameDuplicateError with code dataset_name_duplicate. External knowledge API names must be unique within a tenant.
Source
Thrown at api/controllers/console/datasets/external.py:241
current_tenant_id: str,
current_user: Account,
):
ExternalDatasetService.validate_api_list(req_data.settings)
# The role of the current user in the ta table must be admin, owner, or editor, or dataset_operator
if not current_user.is_dataset_editor:
raise Forbidden()
try:
external_knowledge_api = ExternalDatasetService.create_external_knowledge_api(
tenant_id=current_tenant_id,
user_id=current_user.id,
args=req_data.model_dump(),
session=session,
)
except services.errors.dataset.DatasetNameDuplicateError:
raise DatasetNameDuplicateError()
return external_knowledge_api_response(external_knowledge_api, session=session).model_dump(mode="json"), 201
@console_ns.route("/datasets/external-knowledge-api/<uuid:external_knowledge_api_id>")
class ExternalApiTemplateApi(Resource):
@console_ns.doc("get_external_api_template")
@console_ns.doc(description="Get external knowledge API template details")
@console_ns.doc(params={"external_knowledge_api_id": "External knowledge API ID"})
@console_ns.response(
200,
"External API template retrieved successfully",
console_ns.models[ExternalKnowledgeApiResponse.__name__],
)
@console_ns.response(404, "Template not found")
@setup_required
@login_required
@account_initialization_requiredView on GitHub (pinned to ef8544b173)
Solutions
- Choose a unique name for the external knowledge API template.
- Before retrying after an ambiguous failure, GET the list to check whether the name already exists; if so, reuse it.
- In import scripts, deduplicate names with a suffix or look-up-first strategy.
Example fix
// before
POST .../external-knowledge-api body: {"name": "my-api"} -> dataset_name_duplicate
// after
GET .../external-knowledge-api -> find existing 'my-api' -> reuse, OR
POST .../external-knowledge-api body: {"name": "my-api-2"} Defensive patterns
Strategy: validation
Validate before calling
async function createExternalApiUnique(name, settings) {
const existing = await fetch('/console/api/datasets/external-knowledge-api').then(r => r.json()).then(d => d.data || []);
const match = existing.find(t => t.name === name);
if (match) return match; // reuse
return fetch('/console/api/datasets/external-knowledge-api', {
method: 'POST', headers: {'Content-Type': 'application/json'},
body: JSON.stringify({name, settings}),
});
} Type guard
const isUniqueName = (name, existing) => typeof name === 'string' && name.length > 0 && !existing.some(t => t.name === name);
Try / catch
try { return await createExternalApi(name, settings); }
catch (e) {
if (e.code === 'dataset_name_duplicate') { return await reuseOrCreateWithSuffix(name, settings); }
throw e;
} Prevention
- List existing external knowledge APIs before creating one.
- On duplicate, reuse the existing template rather than retrying the same name.
- Suffix or namespace generated names in automation to avoid collisions.
When it happens
Trigger: POST /console/api/datasets/external-knowledge-api with a Body.name that matches an existing external knowledge API name in the current tenant.
Common situations: User retries a create after a network blip and the first call already succeeded; import/migration tooling creates templates with colliding names; UI does not refresh the list before re-submitting.
Related errors
- API template not found.
- export response missing data field
- usage_missing_arg
- patched environment variable ids must be unique
- deleted environment variable ids must be unique
AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12).
Data as JSON: /api/errors/2c467c0779cb989e.
Report an issue: GitHub.