Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(api): make CreatorUserRole accept both `end-user` and `end_user` (#33638)

wangxiaolei387e5a345ff9
diff --git a/api/models/enums.py b/api/models/enums.py
index 6af74cddc8c..6499c5b4436 100644
--- a/api/models/enums.py
+++ b/api/models/enums.py
@@ -11,6 +11,13 @@ class CreatorUserRole(StrEnum):
ACCOUNT = "account"
END_USER = "end_user"
+ @classmethod
+ def _missing_(cls, value):
+ if value == "end-user":
+ return cls.END_USER
+ else:
+ return super()._missing_(value)
+
class WorkflowRunTriggeredFrom(StrEnum):
DEBUGGING = "debugging"
diff --git a/api/tests/unit_tests/models/test_enums_creator_user_role.py b/api/tests/unit_tests/models/test_enums_creator_user_role.py
new file mode 100644
index 00000000000..6317166fdcd
--- /dev/null
+++ b/api/tests/unit_tests/models/test_enums_creator_user_role.py
@@ -0,0 +1,19 @@
+import pytest
+
+from models.enums import CreatorUserRole
+
+
+def test_creator_user_role_missing_maps_hyphen_to_enum():
+ # given an alias with hyphen
+ value = "end-user"
+
+ # when converting to enum (invokes StrEnum._missing_ override)
+ role = CreatorUserRole(value)
+
+ # then it should map to END_USER
+ assert role is CreatorUserRole.END_USER
+
+
+def test_creator_user_role_missing_raises_for_unknown():
+ with pytest.raises(ValueError):
+ CreatorUserRole("unknown")