Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: callable for template_fields #37028

Merged
merged 11 commits into from
Jun 11, 2024

Conversation

raphaelauv
Copy link
Contributor

@raphaelauv raphaelauv commented Jan 26, 2024

following discussion of #35844

revert templating from #31362

@raphaelauv raphaelauv force-pushed the feature/template_fields_callable branch from 6adddf1 to 27f2764 Compare January 26, 2024 11:37
@raphaelauv raphaelauv marked this pull request as ready for review January 29, 2024 22:22
Copy link
Contributor

@dirrao dirrao left a comment

Choose a reason for hiding this comment

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

Can you add the test cases for the change?

@uranusjr
Copy link
Member

I wonder if we should turn the return value of the callable into a template and render that. Since a callable can do whatever it wants, supporting returning a template seems redundant and may induce some confusing behaviours (the same as template_fields already does in some edge cases).

As a side note, I wonder if the callable should take context as an argument.

Copy link

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 Mar 16, 2024
@raphaelauv raphaelauv force-pushed the feature/template_fields_callable branch from 5bcb001 to 4cfb46b Compare March 20, 2024 23:07
@github-actions github-actions bot removed the stale Stale PRs per the .github/workflows/stale.yml policy file label Mar 21, 2024
@raphaelauv raphaelauv force-pushed the feature/template_fields_callable branch from 4cfb46b to d6a858a Compare March 21, 2024 12:59
Copy link
Member

@uranusjr uranusjr left a comment

Choose a reason for hiding this comment

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

Yeah after some more thought I really do not like the fact that the return value gets treated as a template string. The callable should just return the rendered value instead. This is what we do with XComArg—a resolved XCom value is treated as-is, not rendered again as a template.

Copy link

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 May 23, 2024
@raphaelauv
Copy link
Contributor Author

no stale

@raphaelauv raphaelauv force-pushed the feature/template_fields_callable branch from d6a858a to 520170b Compare May 30, 2024 14:13
@eladkal eladkal removed the stale Stale PRs per the .github/workflows/stale.yml policy file label May 30, 2024
@raphaelauv
Copy link
Contributor Author

@uranusjr thanks for your review , wdyt of this second implementation ?

@raphaelauv raphaelauv force-pushed the feature/template_fields_callable branch from 520170b to 3fe6ec3 Compare May 30, 2024 16:43
@raphaelauv raphaelauv requested a review from uranusjr May 30, 2024 16:44
@uranusjr
Copy link
Member

uranusjr commented Jun 3, 2024

The idea looks fine to me, but this should be a part of _do_render_template_fields instead, or even somewhere deeper in the call chain. render_template_fields is an override point for users and we shouldn’t put logic in there where people can shadow.

I wonder if we should make this a part of render_template.

@raphaelauv raphaelauv force-pushed the feature/template_fields_callable branch from 9e72a7b to ebe6e33 Compare June 3, 2024 13:27
@raphaelauv
Copy link
Contributor Author

@uranusjr thanks again, I did the change

@uranusjr
Copy link
Member

uranusjr commented Jun 4, 2024

Also we need documentation on this.

@raphaelauv
Copy link
Contributor Author

Also we need documentation on this.

yeah I will when we find the final implementation

@uranusjr
Copy link
Member

uranusjr commented Jun 4, 2024

Design looks good now to me.

@raphaelauv raphaelauv requested a review from potiuk as a code owner June 4, 2024 12:02
@raphaelauv raphaelauv force-pushed the feature/template_fields_callable branch from fa4dfda to f6c93b5 Compare June 5, 2024 11:11
@raphaelauv
Copy link
Contributor Author

@uranusjr could you pls review the doc commit , thanks

Copy link
Member

@uranusjr uranusjr left a comment

Choose a reason for hiding this comment

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

I touched up the documentation so the full document reads better. Looks good to me now. Does this work with nested fields?

PythonOperator(
    ...,
    op_kwargs={"foo": render_foo},  # Is this callable rendered?
)

We probably should not allow this since it would be a bit confusing.

@raphaelauv
Copy link
Contributor Author

thanks for the doc , I added a new test about nested fields

Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

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

Very good idea and implementation.

@potiuk potiuk merged commit 6c7aa4b into apache:main Jun 11, 2024
51 checks passed
@raphaelauv raphaelauv deleted the feature/template_fields_callable branch June 11, 2024 22:03
@ephraimbuddy ephraimbuddy added this to the Airflow 2.10.0 milestone Jul 1, 2024
@ephraimbuddy ephraimbuddy added the type:new-feature Changelog: New Features label Jul 1, 2024
romsharon98 pushed a commit to romsharon98/airflow that referenced this pull request Jul 26, 2024
---------

Co-authored-by: raphaelauv <[email protected]>
Co-authored-by: Tzu-ping Chung <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:new-feature Changelog: New Features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants