Skip to content

Conversation

@highlyavailable
Copy link
Contributor

Fixes #50977

Problem

Two TestFileTaskLogHandler tests were marked with @pytest.mark.xfail because they were written for the old logging format but needed to work with the new structlog-based logging system:

  • test_file_task_handler_when_ti_value_is_invalid
  • test_file_task_handler

These tests were failing because they expected log data as strings but were receiving StructuredLogMessage objects from the new structlog implementation.

Solution

  1. Removed @pytest.mark.xfail decorators - (tests now pass instead of being marked as expected failures)

  2. Updated test_file_task_handler assertion logic:

    • Before: assert re.search(target_re, log_content) (regex matching on string content)
    • After: assert any("test" in event for event in events(logs)) (substring matching on event messages)
  3. No changes needed for test_file_task_handler_when_ti_value_is_invalid - This test actually already used direct object access (logs[0].event) which works correctly with StructuredLogMessage objects

@boring-cyborg
Copy link

boring-cyborg bot commented May 23, 2025

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@eladkal eladkal requested a review from kaxil May 26, 2025 11:22
@kaxil
Copy link
Member

kaxil commented May 27, 2025

Tests are failing:

FAILED airflow-core/tests/unit/utils/test_log_handlers.py::TestFileTaskLogHandler::test_file_task_handler_when_ti_value_is_invalid - AttributeError: 'RuntimeTaskInstance' object has no attribute 'log'
FAILED airflow-core/tests/unit/utils/test_log_handlers.py::TestFileTaskLogHandler::test_file_task_handler - AttributeError: 'RuntimeTaskInstance' object has no attribute 'log'

@highlyavailable
Copy link
Contributor Author

Tests are failing:

FAILED airflow-core/tests/unit/utils/test_log_handlers.py::TestFileTaskLogHandler::test_file_task_handler_when_ti_value_is_invalid - AttributeError: 'RuntimeTaskInstance' object has no attribute 'log'
FAILED airflow-core/tests/unit/utils/test_log_handlers.py::TestFileTaskLogHandler::test_file_task_handler - AttributeError: 'RuntimeTaskInstance' object has no attribute 'log'

Hey @kaxil, this commit fixes the failing tests. Thanks for the feedback.

@kaxil kaxil force-pushed the fix-structlog-test-log-handlers branch from 3c0f861 to 252bfb8 Compare June 2, 2025 18:33
@kaxil
Copy link
Member

kaxil commented Jun 2, 2025

Thanks, I have rebased your PR on main, let's see what the CI says

Copy link
Contributor

@o-nikolas o-nikolas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix, thanks for circling back and ensuring these tests pass :)

…l decorators and update assertions for StructuredLogMessage objects (fixes apache#50977)
…ests

  Use logging.getLogger(TASK_LOGGER) directly in task callables instead of
  ti.log to avoid AttributeError when RuntimeTaskInstance is created during
  test execution.
@kaxil kaxil force-pushed the fix-structlog-test-log-handlers branch from 252bfb8 to 967d3ed Compare June 9, 2025 19:47
def task_callable(ti):
ti.log.info("test")
def task_callable():
logger = logging.getLogger(TASK_LOGGER)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use structlog.get_logger instead?

@github-actions
Copy link

github-actions bot commented Aug 8, 2025

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Aug 8, 2025
@github-actions github-actions bot closed this Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale PRs per the .github/workflows/stale.yml policy file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port TestFileTaskLogHandler tests to new Structlog logs

4 participants