Skip to content

Commit 3ee8100

Browse files
UN-2813 [FIX] Sanitize CLI queue list to prevent invalid queue names
Fix bug where malformed --queues input causes worker to crash. **Problem:** CLI queue list was returned without sanitization, allowing invalid queue names to reach Celery/Temporal and crash the worker: Examples of problematic input: - `--queues foo,` → ["foo", ""] (empty string) - `--queues foo, bar` → ["foo", " bar"] (whitespace) - `--queues ,,,` → ["", "", ""] (all empty) **Inconsistency:** Environment variable TASK_QUEUES was properly sanitized (line 97), but CLI --queues was not (line 88-90), creating inconsistent behavior. **Solution:** Apply same sanitization to CLI queues as env queues: ```python queues = [q.strip() for q in cli_queues if q and q.strip()] if not queues: raise ValueError("No queues specified via --queues after trimming...") ``` **Changes:** 1. ✅ Strip whitespace from each queue name 2. ✅ Filter out empty/whitespace-only entries 3. ✅ Validate at least one valid queue remains 4. ✅ Fail fast with clear error message **Impact:** - ✅ Prevents worker crashes from malformed queue input - ✅ Consistent sanitization for CLI and env vars - ✅ Better error messages for invalid input - ✅ Worker starts reliably with clean queue list **Examples:** ```bash # Before: Crashes --queues foo, # → ["foo", ""] # After: Works --queues foo, # → ["foo"] # Before: Silent corruption --queues " foo , bar " # → [" foo ", " bar "] # After: Clean --queues " foo , bar " # → ["foo", "bar"] ``` Resolves: CodeRabbit comment #2386596269 Related: #1555
1 parent 881e0e5 commit 3ee8100

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

  • task-backend/src/unstract/task_backend

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,13 @@ def _resolve_queues(self, cli_queues: list | None) -> list:
8686

8787
# Priority 1: CLI arguments (explicit deployment)
8888
if cli_queues:
89-
logger.info(f"Using queues from CLI arguments: {', '.join(cli_queues)}")
90-
return cli_queues
89+
queues = [q.strip() for q in cli_queues if q and q.strip()]
90+
if not queues:
91+
raise ValueError(
92+
"No queues specified via --queues after trimming empty entries."
93+
)
94+
logger.info(f"Using queues from CLI arguments: {', '.join(queues)}")
95+
return queues
9196

9297
# Priority 2: Environment variable (dev convenience only)
9398
environment = os.getenv("ENVIRONMENT", "prod").lower()

0 commit comments

Comments
 (0)