-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Bug Report: Critical Job Queue Validation Failure
Summary
High Severity Bug: The validate_or_get_queue function in api/utils/job_queue.py contains a type mismatch bug that causes job submission to fail when users rely on automatic queue selection based on job type.
Bug Location
- File:
api/utils/job_queue.py - Function:
validate_or_get_queue - Lines: 221-224
Problem Description
The Bug
# Line 221 - Assigns a queue OBJECT to the queue variable
queue = next(q for q in valid_queues if q.queue_name == recommended_queue)
# Line 224 - Compares queue OBJECT against list of queue NAME STRINGS
if queue not in valid_queue_names:
raise ValueError(f"User does not have access to {queue}. Valid queues: {valid_queue_names}")What Happens
- When a user submits a job with an empty queue name and a job type
- The function finds the correct recommended queue object (line 221)
- But then checks if this queue object exists in a list of queue name strings (line 224)
- This comparison always fails because you're comparing
<QueueObject>to["queue-name-1", "queue-name-2"] - The function raises a ValueError claiming the user doesn't have access to the queue
Error Message Example
ValueError: User does not have access to <api.models.job_queue.JobQueue object at 0x12345>. Valid queues: ['maap-dps-worker-8gb', 'maap-dps-worker-16gb']
Impact Assessment
Severity: HIGH 🔴
This bug breaks core job submission functionality.
Affected Workflows
- ❌ Job submission without explicit queue selection
- ❌ Algorithm-specific queue recommendations
- ❌ Any workflow relying on
job_typeto determine queue - ❌ Default queue fallback for job types
Production Impact
- Users cannot submit jobs that rely on automatic queue selection
- Job submission forms that don't require queue selection will fail
- Algorithms with specific queue requirements will be unusable
Reproduction Steps
- Call
validate_or_get_queue("", "some-job-type", user_id)where:- Empty string for queue name (triggering automatic selection)
- Valid job type that has a recommended queue
- Valid user ID with queue access
- Function will find the recommended queue but immediately fail validation
- ValueError will be raised despite user having access to the queue
Root Cause Analysis
Type Confusion
The queue variable is used for two different types:
- Input: String (queue name)
- Runtime: Object (queue instance after line 221)
- Validation: Compared against strings (line 224)
Logic Flow Issue
# CURRENT BUGGY FLOW:
queue = "" # String: empty queue name
↓
queue = <QueueObject> # Object: recommended queue found
↓
if queue not in ["name1", "name2"]: # Object compared to strings → Always True
raise ValueError # Always raises errorProposed Fix
Option 1: Return Early (Recommended)
if queue is None or queue == "":
if job_type is None:
default_queue = next(q for q in valid_queues if q.is_default)
return default_queue
recommended_queue = hysds.get_recommended_queue(job_type)
return next(q for q in valid_queues if q.queue_name == recommended_queue) # Return directlyOption 2: Use Queue Name
if queue is None or queue == "":
if job_type is None:
default_queue = next(q for q in valid_queues if q.is_default)
return default_queue
recommended_queue = hysds.get_recommended_queue(job_type)
queue = recommended_queue # Keep as string, don't convert to object yetTesting
Current Test Gap
The existing tests in test/api/utils/test_hysds_util.py mock away this validation logic, which is why the bug wasn't caught.
Recommended Test Cases
def test_empty_queue_with_job_type_returns_recommended_queue(self):
"""Test that empty queue + job_type returns recommended queue without error."""
# Setup valid user queues including recommended queue
# Call validate_or_get_queue("", "job-type", user_id)
# Assert returns correct queue object without raising ValueError
def test_automatic_queue_selection_integration(self):
"""Integration test for automatic queue selection workflow."""
# Test the complete flow from job submission to queue selectionDiscovered By
Identified during Phase 2.4.1 of test implementation when modernizing HySDS utility tests. The bug was exposed when implementing comprehensive integration tests with proper mocking patterns.
Priority
CRITICAL - This bug blocks core job submission functionality and should be fixed immediately.
Labels
bugpriority: highcomponent: job-queueaffects: job-submissiontype: logic-error
Reporter: Test Implementation Team
Date: 2025-07-02
Test File: test/api/utils/test_hysds_utilities.py