Skip to content

Commit eba99a1

Browse files
authored
Fix v1 fallback to handle HTTP 405 from update-task-v2 on older Conductor (#388)
1 parent c2e3760 commit eba99a1

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

src/conductor/client/automator/async_task_runner.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -841,11 +841,12 @@ async def __async_update_task(self, task_result: TaskResult):
841841
)
842842
return None
843843
except ApiException as e:
844-
if e.status == 404 and self._use_update_v2:
844+
if e.status in (404, 405) and self._use_update_v2:
845845
logger.warning(
846-
"Server does not support update-task-v2 endpoint (HTTP 404). "
846+
"Server does not support update-task-v2 endpoint (HTTP %d). "
847847
"Falling back to v1 update endpoint. "
848-
"Upgrade your Conductor instance to v5+ to enable the v2 endpoint."
848+
"Upgrade your Conductor instance to v5+ to enable the v2 endpoint.",
849+
e.status,
849850
)
850851
self._use_update_v2 = False
851852
# Retry immediately with v1

src/conductor/client/automator/task_runner.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -871,11 +871,12 @@ def __update_task(self, task_result: TaskResult):
871871
)
872872
return None
873873
except ApiException as e:
874-
if e.status == 404 and self._use_update_v2:
874+
if e.status in (404, 405) and self._use_update_v2:
875875
logger.warning(
876-
"Server does not support update-task-v2 endpoint (HTTP 404). "
876+
"Server does not support update-task-v2 endpoint (HTTP %d). "
877877
"Falling back to v1 update endpoint. "
878-
"Upgrade your Orkes instance to v5+ to enable the v2 endpoint."
878+
"Upgrade your Orkes instance to v5+ to enable the v2 endpoint.",
879+
e.status,
879880
)
880881
self._use_update_v2 = False
881882
# Retry immediately with v1

tests/unit/automator/test_task_runner_coverage.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,29 @@ def test_update_task_v2_404_falls_back_to_v1(self):
829829
mock_v1.assert_called_once()
830830
self.assertIsNone(result)
831831

832+
@patch('time.sleep', Mock(return_value=None))
833+
def test_update_task_v2_405_falls_back_to_v1(self):
834+
"""When server returns 405 for v2 endpoint (older Conductor), should fall back to v1."""
835+
worker = MockWorker('test_task')
836+
task_runner = TaskRunner(worker=worker)
837+
838+
task_result = TaskResult(
839+
task_id='test_id',
840+
workflow_instance_id='wf_id',
841+
worker_id=worker.get_identity(),
842+
status=TaskResultStatus.COMPLETED
843+
)
844+
845+
with patch.object(TaskResourceApi, 'update_task_v2',
846+
side_effect=ApiException(status=405)) as mock_v2, \
847+
patch.object(TaskResourceApi, 'update_task', return_value='ok') as mock_v1:
848+
result = task_runner._TaskRunner__update_task(task_result)
849+
850+
mock_v2.assert_called_once()
851+
mock_v1.assert_called_once()
852+
self.assertIsNone(result)
853+
self.assertFalse(task_runner._use_update_v2)
854+
832855
@patch('time.sleep', Mock(return_value=None))
833856
def test_update_task_v2_404_sets_v1_flag(self):
834857
"""After a 404 on v2, _use_update_v2 flag must be False."""

0 commit comments

Comments
 (0)