langgenius/dify · error · ValueError
deleted environment variable ids must be unique
Error message
deleted environment variable ids must be unique
What it means
Raised by SyncEnvironmentVariablePatchPayload.validate_patch when deleted_environment_variable_ids contains duplicate entries (api/controllers/console/app/workflow.py:133-134). Deleting the same id twice is meaningless and indicates a client bug; validation rejects it. Surfaced as a Pydantic ValidationError (400).
Source
Thrown at api/controllers/console/app/workflow.py:134
description: NotRequired[str | None]
class SyncEnvironmentVariablePatchPayload(BaseModel):
environment_variables: list[dict[str, Any]] = Field(default_factory=list)
deleted_environment_variable_ids: list[str] = Field(default_factory=list)
@model_validator(mode="after")
def validate_patch(self) -> Self:
"""Require stable, disjoint IDs so the service can merge the patch deterministically."""
upsert_ids = [variable.get("id") for variable in self.environment_variables]
if any(not isinstance(variable_id, str) or not variable_id for variable_id in upsert_ids):
raise ValueError("patched environment variables require an id")
if len(set(upsert_ids)) != len(upsert_ids):
raise ValueError("patched environment variable ids must be unique")
if any(not variable_id for variable_id in self.deleted_environment_variable_ids):
raise ValueError("deleted environment variable ids must not be empty")
if len(set(self.deleted_environment_variable_ids)) != len(self.deleted_environment_variable_ids):
raise ValueError("deleted environment variable ids must be unique")
if set(upsert_ids).intersection(self.deleted_environment_variable_ids):
raise ValueError("an environment variable cannot be upserted and deleted in the same patch")
return self
class SyncDraftWorkflowPayload(BaseModel):
model_config = ConfigDict(extra="forbid")
graph: dict[str, Any]
features: dict[str, Any]
hash: str | None = None
is_collaborative: bool = Field(default=False, alias="_is_collaborative")
environment_variable_patch: SyncEnvironmentVariablePatchPayload | None = None
conversation_variables: list[dict[str, Any]] = Field(
default_factory=list,
)
View on GitHub (pinned to ef8544b173)
Solutions
- Deduplicate deleted_environment_variable_ids before submit: `[...new Set(ids)]`.
- Track deletions in a Set on the client so duplicates cannot accumulate.
- Disable the delete control after the variable is marked for deletion.
Example fix
// before: duplicate in delete list deleted_environment_variable_ids: ['a', 'a', 'b'] // after: dedup deleted_environment_variable_ids: [...new Set(['a', 'a', 'b'])]
Defensive patterns
Strategy: validation
Validate before calling
// Deduplicate delete ids before submit payload.deleted_environment_variable_ids = [...new Set(payload.deleted_environment_variable_ids)]
Type guard
function uniqueDeletes(ids) {
return new Set(ids).size === ids.length
} Prevention
- Track deletions in a Set on the client.
- Dedupe before submit.
When it happens
Trigger: The deleted_environment_variable_ids array has the same id more than once. Common with double-add handlers or merging multiple delete selections without dedup.
Common situations: UI delete-action fired twice for the same variable; merging selected-for-delete sets without dedup; test payload reused; event handler firing on both click and keypress.
Related errors
- patched environment variable ids must be unique
- patched environment variables require an id
- deleted environment variable ids must not be empty
- an environment variable cannot be upserted and deleted in th
- Unsupported environment variable value type: {value_type}
AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12).
Data as JSON: /api/errors/4b7a838e0f428e65.
Report an issue: GitHub.