-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
get_current_context not present in user_defined_macros #33217
Comments
Hello @potiuk @raphaelauv, I would like to take this issue. Will submit PR in a few days. I'm not sure how I can assign it to myself though. |
assigned |
FWIW, this can be used as a workaround (i.e. pass the from airflow.models import DAG
from airflow.operators.python import PythonOperator
from airflow.utils.dates import days_ago
def macro_run_id(dag):
a = dag.schedule_interval.replace("@", "")
if a == "None":
a = "manual"
return a
with DAG(
dag_id="example2",
start_date=days_ago(61),
user_defined_macros={"macro_run_id": macro_run_id},
schedule_interval="@monthly",
):
def toto(arg):
print(arg)
PythonOperator(task_id="toot", python_callable=toto, op_kwargs={"arg": "{{ macro_run_id(dag) }}"}) Task log:
|
Thanks @josh-fell , it's a great hack for my (specific) use case 👍👍👍 |
@ivan-afonichkin I found that this issue was fixed at 2.7.1 version.we may not upgrade airflow now , so is there a way to fix this issue under 2.7.1 version? |
You can attempt to patch it manually - source of airflow is fully available and you might want to patch your source. But I heartily recommend to just upgrade airflow. Every single airflow release contains 10s of fixes to known problems in previous versions, a lot of them contains fixes to security issues and generally - almost by defintion - when you do not run latest version, you run a version that contains known bugs and security fixes. So "upgrade airflow to latest version" is abaolutely best way that you should proceed. You have to remember that even if it costs some time to upgrade, it will likely cost you (and your organisation) a lot more to NOT upgrade - because of known bugs that are fixed and potential risk of security issues you have not applied (and in the future when acts like CRA (Cyber Resilience Act ) in EU and similar in the US will be approved and become the law (it will be passed in EU in a month or two) your organisation will have to upgrade to latest security-fixed version of software anyway and it will cost penalties if they don't, so I suggest get used to situation that you upgrade software as soon as it is released. |
Apache Airflow version
2.6.3
What happened
get_current_context() fail in a user_defined_macros
give
What you think should happen instead
User macros should be able to access to the current context
How to reproduce
Operating System
ubuntu 22.04
Versions of Apache Airflow Providers
No response
Deployment
Other
Deployment details
No response
Anything else
No response
Are you willing to submit PR?
Code of Conduct
The text was updated successfully, but these errors were encountered: