{"record":{"id":"4b7a838e0f428e65","repo":"langgenius/dify","slug":"deleted-environment-variable-ids-must-be-unique","errorCode":null,"errorMessage":"deleted environment variable ids must be unique","messagePattern":"deleted environment variable ids must be unique","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"api/controllers/console/app/workflow.py","lineNumber":134,"sourceCode":"    description: NotRequired[str | None]\n\n\nclass SyncEnvironmentVariablePatchPayload(BaseModel):\n    environment_variables: list[dict[str, Any]] = Field(default_factory=list)\n    deleted_environment_variable_ids: list[str] = Field(default_factory=list)\n\n    @model_validator(mode=\"after\")\n    def validate_patch(self) -> Self:\n        \"\"\"Require stable, disjoint IDs so the service can merge the patch deterministically.\"\"\"\n        upsert_ids = [variable.get(\"id\") for variable in self.environment_variables]\n        if any(not isinstance(variable_id, str) or not variable_id for variable_id in upsert_ids):\n            raise ValueError(\"patched environment variables require an id\")\n        if len(set(upsert_ids)) != len(upsert_ids):\n            raise ValueError(\"patched environment variable ids must be unique\")\n        if any(not variable_id for variable_id in self.deleted_environment_variable_ids):\n            raise ValueError(\"deleted environment variable ids must not be empty\")\n        if len(set(self.deleted_environment_variable_ids)) != len(self.deleted_environment_variable_ids):\n            raise ValueError(\"deleted environment variable ids must be unique\")\n        if set(upsert_ids).intersection(self.deleted_environment_variable_ids):\n            raise ValueError(\"an environment variable cannot be upserted and deleted in the same patch\")\n        return self\n\n\nclass SyncDraftWorkflowPayload(BaseModel):\n    model_config = ConfigDict(extra=\"forbid\")\n\n    graph: dict[str, Any]\n    features: dict[str, Any]\n    hash: str | None = None\n    is_collaborative: bool = Field(default=False, alias=\"_is_collaborative\")\n    environment_variable_patch: SyncEnvironmentVariablePatchPayload | None = None\n    conversation_variables: list[dict[str, Any]] = Field(\n        default_factory=list,\n    )\n\n","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/controllers/console/app/workflow.py#L116-L152","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: duplicate in delete list\ndeleted_environment_variable_ids: ['a', 'a', 'b']\n// after: dedup\ndeleted_environment_variable_ids: [...new Set(['a', 'a', 'b'])]","handlingStrategy":"validation","validationCode":"// Deduplicate delete ids before submit\npayload.deleted_environment_variable_ids = [...new Set(payload.deleted_environment_variable_ids)]","typeGuard":"function uniqueDeletes(ids) {\n  return new Set(ids).size === ids.length\n}","tryCatchPattern":null,"preventionTips":["Track deletions in a Set on the client.","Dedupe before submit."],"tags":["workflow","environment-variables","validation","duplicate","api"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}