Details
-
Bug
-
Resolution: Done
-
Low
-
5.14.3.1
-
Severity 2 - Major
-
Description
Summary
- Create several plans and assign them to some agent
- Change few records in DB table agent_assignment to have executable_id which doesn't have corresponding record in build table
- Open agent assignment page and see updated records were disappear from assignments list
- Try to remove some plan from agent assignment page
- It's removed but other records removed as well
Reason
Code to remove agent assignment removes all assignments for given agent and then iterates over them and create other assignment except removed by user. If it can't recreate existing assignment (plan doesn't exist or user have no permission to given plan/project) it drops remaining records and exits.
Workaround
Remove DB records from agent_assignment table which references to non existing plans. And then functionality should work as expected
List of orphaned records
SELECT q.title AS agent_name, aa.* FROM agent_assignment aa LEFT JOIN build b ON (aa.executable_id = b.build_id AND b.build_type = 'CHAIN') LEFT JOIN queue q ON aa.executor_id = q.queue_id WHERE aa.executable_type = 'PLAN' AND b.build_id IS NULL AND aa.executor_type = 'AGENT' UNION SELECT q.title AS agent_name, aa.* FROM agent_assignment aa LEFT JOIN build b ON (aa.executable_id = b.build_id AND b.build_type = 'JOB') LEFT JOIN queue q ON aa.executor_id = q.queue_id WHERE aa.executable_type = 'JOB' AND b.build_id IS NULL AND aa.executor_type = 'AGENT';