Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion airflow-core/src/airflow/utils/log/file_task_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,10 @@ def read(
if try_number is None:
try_number = task_instance.try_number

if try_number == 0 and task_instance.state == TaskInstanceState.SKIPPED:
if try_number == 0 and task_instance.state in (
TaskInstanceState.SKIPPED,
TaskInstanceState.UPSTREAM_FAILED,
):
logs = [StructuredLogMessage(event="Task was skipped, no logs available.")]
return chain(logs), {"end_of_log": True}

Expand Down
25 changes: 13 additions & 12 deletions airflow-core/tests/unit/utils/test_log_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
)
from tests_common.test_utils.markers import skip_if_force_lowest_dependencies_marker

pytestmark = [pytest.mark.db_test, pytest.mark.xfail()]
pytestmark = [pytest.mark.db_test]

DEFAULT_DATE = pendulum.datetime(2016, 1, 1)
TASK_LOGGER = "airflow.task"
Expand Down Expand Up @@ -156,7 +156,8 @@ def task_callable(ti):
# Remove the generated tmp log file.
os.remove(log_filename)

def test_file_task_handler_when_ti_is_skipped(self, dag_maker):
@pytest.mark.parametrize("ti_state", [TaskInstanceState.SKIPPED, TaskInstanceState.UPSTREAM_FAILED])
def test_file_task_handler_when_ti_is_not_run(self, dag_maker, ti_state):
def task_callable(ti):
ti.log.info("test")

Expand All @@ -170,10 +171,10 @@ def task_callable(ti):
ti = TaskInstance(task=task, run_id=dagrun.run_id, dag_version_id=dag_version.id)

ti.try_number = 0
ti.state = State.SKIPPED
ti.state = ti_state

logger = ti.log
ti.log.disabled = False
logger = logging.getLogger(TASK_LOGGER)
logger.disabled = False

file_handler = next(
(handler for handler in logger.handlers if handler.name == FILE_TASK_HANDLER), None
Expand Down Expand Up @@ -295,8 +296,8 @@ def test_file_task_handler_with_multiple_executors(
ti.executor = executor_name
ti.try_number = 1
ti.state = TaskInstanceState.RUNNING
logger = ti.log
ti.log.disabled = False
logger = logging.getLogger(TASK_LOGGER)
logger.disabled = False

file_handler = next(
(handler for handler in logger.handlers if handler.name == FILE_TASK_HANDLER), None
Expand Down Expand Up @@ -344,8 +345,8 @@ def task_callable(ti):
ti.try_number = 2
ti.state = State.RUNNING

logger = ti.log
ti.log.disabled = False
logger = logging.getLogger(TASK_LOGGER)
logger.disabled = False

file_handler = next(
(handler for handler in logger.handlers if handler.name == FILE_TASK_HANDLER), None
Expand Down Expand Up @@ -396,8 +397,8 @@ def task_callable(ti):
ti.try_number = 1
ti.state = State.RUNNING

logger = ti.log
ti.log.disabled = False
logger = logging.getLogger(TASK_LOGGER)
logger.disabled = False

file_handler = next(
(handler for handler in logger.handlers if handler.name == FILE_TASK_HANDLER), None
Expand All @@ -413,7 +414,7 @@ def task_callable(ti):
assert log_filename.endswith("1.log"), log_filename

# mock to generate 2000 lines of log, the total size is larger than max_bytes_size
for i in range(1, 2000):
for i in range(1, 3000):
logger.info("this is a Test. %s", i)

# this is the rotate log file
Expand Down
Loading