Skip to content

Comments

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

Merged
kaxil merged 2 commits intoapache: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 intoapache:mainfrom
prdai:docs/54380-fix-dag-log-in-params-example

Conversation

@prdai
Copy link
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 the backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch label Aug 13, 2025
@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

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>
meldiner pushed a commit to faros-ai/airflow that referenced this pull request Feb 6, 2026
…meter access (apache#54450) (apache#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

Labels

backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch kind:documentation

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