Lee-W commented on issue #54265:
URL: https://github.com/apache/airflow/issues/54265#issuecomment-3170245682

   here is an example code I use to test. to reproduce this bug, we'll need to 
send `"chosen_options": []`.
   
   ```python
   import requests
   
   # manual input required
   dag_run_id = <Dag run ID>
   chosen_options = ["option 2"]
   multiple_chosen_options = ["option 4", "option 6"]
   
   params_input = {"information": "test info"}
   
   # ---
   
   host = "http://localhost:28080";
   dag_id = "example_hitl_operator"
   
   
   # authentication
   token_endpoint = "/auth/token"
   resp = requests.post(f"{host}{token_endpoint}", json={"username": "admin", 
"password": "admin"})
   token = resp.json()["access_token"]
   headers = {"Authorization": f"Bearer {token}"}
        
   # get all hitl details                
   get_all_hitl_details_endpoint = "/api/v2/hitlDetails/"
   resp = requests.get(f"{host}{get_all_hitl_details_endpoint}", 
headers=headers)
   resp.json()
   
   # get hitl detail for task "wait_for_option"
   task_id = "wait_for_option"
   hitl_ti_endpoint = f"/api/v2/hitlDetails/{dag_id}/{dag_run_id}/{task_id}"
   resp = requests.get(f"{host}{hitl_ti_endpoint}", headers=headers)
   resp.json()
   
   # response to "wait_for_option"
   data = {"chosen_options": chosen_options}
   resp = requests.patch(f"{host}{hitl_ti_endpoint}", headers=headers, 
json=data)
   resp.json()
   
   # response to "wait_for_input"
   task_id = "wait_for_input"
   hitl_ti_endpoint = f"/api/v2/hitlDetails/{dag_id}/{dag_run_id}/{task_id}"
   data = {"params_input": params_input, "chosen_options": ["OK"]}
   resp = requests.patch(f"{host}{hitl_ti_endpoint}", headers=headers, 
json=data)
   resp.json()
   
   # response to "wait_for_multiple_options"
   task_id = "wait_for_multiple_options"
   hitl_ti_endpoint = f"/api/v2/hitlDetails/{dag_id}/{dag_run_id}/{task_id}"
   data = {"chosen_options": multiple_chosen_options}
   resp = requests.patch(f"{host}{hitl_ti_endpoint}", headers=headers, 
json=data)
   resp.json()
   
   # response to "valid_input_and_options", need to wait for the tasks above
   task_id = "valid_input_and_options"
   hitl_ti_endpoint = f"/api/v2/hitlDetails/{dag_id}/{dag_run_id}/{task_id}"
   data = {"chosen_options": ["Approve"]}
   resp = requests.patch(f"{host}{hitl_ti_endpoint}", headers=headers, 
json=data)
   resp.json()
   
   # resposne to "choose_a_branch_to_run", need to wait for the tasks above
   task_id = "choose_a_branch_to_run"
   hitl_ti_endpoint = f"/api/v2/hitlDetails/{dag_id}/{dag_run_id}/{task_id}"
   data = {"chosen_options": ["task_1"]}
   resp = requests.patch(f"{host}{hitl_ti_endpoint}", headers=headers, 
json=data)
   resp.json()
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to