Skip to content

Commit 9819f80

Browse files
UN-2813 [FIX] Ensure backend config returns correct backend_type
Fix critical bug where get_backend_config_for_type() returned configs with incorrect backend_type field. **Problem:** When calling get_backend_config_for_type("hatchet") or "temporal", the returned config object had backend_type="celery" (inherited default from BaseWorkerConfig) instead of the requested type. This caused CLI commands like `--backend=temporal` to spin up the wrong backend. **Solution:** - Refactored to use config class map - Pass backend_type explicitly to config constructor - Added proper exception chaining with `from None` **Impact:** - CLI backend selection now works correctly - Config objects have correct backend_type field - Prevents subtle bugs from mismatched backend types **Example:** ```python # Before: config.backend_type = "celery" ❌ config = get_backend_config_for_type("temporal") # After: config.backend_type = "temporal" ✅ config = get_backend_config_for_type("temporal") ``` Resolves: CodeRabbit comment #2386596266 Related: #1555
1 parent 38a1205 commit 9819f80

File tree

1 file changed

+11
-8
lines changed
  • task-backend/src/unstract/task_backend

1 file changed

+11
-8
lines changed

task-backend/src/unstract/task_backend/config.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,14 @@ def get_task_backend_config() -> TaskBackendConfig:
133133

134134
def get_backend_config_for_type(backend_type: str) -> TaskBackendConfig:
135135
"""Get configuration for a specific backend type."""
136-
if backend_type == "celery":
137-
return CeleryWorkerConfig()
138-
elif backend_type == "hatchet":
139-
return HatchetWorkerConfig()
140-
elif backend_type == "temporal":
141-
return TemporalWorkerConfig()
142-
else:
143-
raise ValueError(f"Unsupported backend type: {backend_type}")
136+
config_map = {
137+
"celery": CeleryWorkerConfig,
138+
"hatchet": HatchetWorkerConfig,
139+
"temporal": TemporalWorkerConfig,
140+
}
141+
try:
142+
config_cls = config_map[backend_type]
143+
except KeyError:
144+
raise ValueError(f"Unsupported backend type: {backend_type}") from None
145+
146+
return config_cls(backend_type=backend_type)

0 commit comments

Comments
 (0)