pierrejeambrun commented on code in PR #50175: URL: https://github.com/apache/airflow/pull/50175#discussion_r2086373150
########## airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_log.py: ########## @@ -449,3 +449,28 @@ def test_get_external_log_url( assert response.status_code == expected_status assert response.json() == expected_response + + @pytest.mark.parametrize("try_number", [1, 2]) + def test_log_fetched_from_ti_history_when_try_number_differs(self, try_number, session): + key = self.app.state.secret_key + serializer = URLSafeSerializer(key) + token = serializer.dumps({"download_logs": False}) + + mock_ti = mock.Mock() + # Simulates a mismatch between the current TaskInstance's try_number (=3) + # and the requested try_number (1 or 2). The log should be fetched from TaskInstanceHistory. + mock_ti.try_number = 3 + mock_ti_history = mock.Mock() + + with mock.patch.object(session, "scalar", side_effect=[mock_ti, mock_ti_history]) as _: + response = self.client.get( + f"/dags/{self.DAG_ID}/dagRuns/{self.RUN_ID}/taskInstances/{self.TASK_ID}/logs/{try_number}", + params={"token": token}, + headers={"Accept": "application/json"}, + ) + + assert response.status_code == 200 + Review Comment: Instead of patching the session, which seems to bring lock problems on sqlite, you could add a real TIH record (manually inserting, or running with failures a couple of TI tries). -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org