Skip to content

Docs: fix example to use task context and logger instead of dag.log (#54380)#54450

Merged
kaxil merged 2 commits into
apache:mainfrom
prdai:docs/54380-fix-dag-log-in-params-example
Aug 13, 2025
Merged

Docs: fix example to use task context and logger instead of dag.log (#54380)#54450
kaxil merged 2 commits into
apache:mainfrom
prdai:docs/54380-fix-dag-log-in-params-example

Conversation

@prdai
Copy link
Copy Markdown
Contributor

@prdai prdai commented Aug 13, 2025

Summary

This PR fixes a documentation bug in the "Params" example under core-concepts: the use of dag.log inside the @task.python function. In the current code, dag.log doesn’t exist in TaskFlow DAGs, causing runtime errors when the code is executed.

Changes

  • Replaced dag.log.info(...) with proper usage of task context and Python logging:
    • Used get_current_context() to access runtime values.
    • Used a standard logger (logging.getLogger("airflow.task")) to output parameter values.
- dag.log.info(dag.params['my_int_param'])
+ logger.info(ctx["dag"].params["my_int_param"])

And similarly for user-provided values via params.

Rationale

  • Airflow 3's Task SDK no longer attaches a .log property to DAG, so relying on dag.log is no longer valid.
  • get_current_context() provides a reliable way to access dag.params and params inside tasks.
  • Logging via Python’s logging module (or self.log on operators) aligns with Airflow’s logging model and avoids missing attribute errors.

Fixes

Closes: #54380.

@kaxil kaxil added this to the Airflow 3.0.5 milestone Aug 13, 2025
@kaxil kaxil merged commit 12c3209 into apache:main Aug 13, 2025
54 checks passed
github-actions Bot pushed a commit that referenced this pull request Aug 13, 2025
…meter access (#54450)

(cherry picked from commit 12c3209)

Co-authored-by: Ranuga Disansa <79456372+Programmer-RD-AI@users.noreply.github.com>
@github-actions
Copy link
Copy Markdown
Contributor

Backport successfully created: v3-0-test

Status Branch Result
v3-0-test PR Link

kaxil pushed a commit that referenced this pull request Aug 13, 2025
…meter access (#54450) (#54463)

(cherry picked from commit 12c3209)

Co-authored-by: Ranuga Disansa <79456372+Programmer-RD-AI@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Params example docs : AttributeError: 'DAG' object has no attribute 'log'

3 participants