-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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
[AIP-31] Add lazy way to get Airflow context from a wrapped function #8058
Comments
Just a comment, provide_context is no longer requires in Master: https://github.com/apache/airflow/pull/5990/files/a5d99ed3f3c7b1a815bd2617d3b935bed499f3f7 |
I see, I still think we should implement this lazy resolved context. Using the current approach from master means that signatures can mismatch op_args/op_kwargs and would make it difficult to reason about the function signature:
As you can see this will execute correctly even though the function signature has a an extra argument. This leads to confusion in my personal opinion hence my proposed solution. |
Yup agree, just wanted to make it clear that we don't need provide_context anymore |
My suggested changes:
I think this is a bit of an over-complication - our use case is much simpler than this.
The actual implementation will contain a simple stack data type that is updated before op.execute is called. |
+1 for starting simple, what would you say to make this context a namedtuple? Referencing values is much more easier with namedtuple than with dictionary (no need to remember names). |
Sounds great, but does this imply we also change the context being provided the old way?
|
No, if someone uses |
Saw it on the PR, lgtm as well on making it a function 😄 |
Any updates on this? |
Description
Currently the only way to access the context object from a PythonOperator wrapped function is by setting
provide_context=True
in the Operator. That loads it into the kwargs. This makes the signature of the function become difficult to argue about.Adding a way to lazy get the function when executing the function may be better. Similar to Flask
flask.request
that get populated when the function is executed.Use case / motivation
Use the Airflow context in arbitrary function while keeping the signature of the function stable and easy to reason about.
An idea of implementation would be:
This can be populated by enabling a context manager on the
PythonOperator.execute
function that populates the field (similar to howDagContext
works) and removes it afterwards.The text was updated successfully, but these errors were encountered: