DAG callback context does not have dag_run set in Airflow 3 but it is set in Airflow 2.
#53618
Replies: 6 comments 8 replies
-
|
Just wanted to say that I am facing the same issue when trying to update my code base from Airflow 2 to 3. I have multiple DAG level callback functions that access the context for posting to Teams channels. I am only getting context object of this type but am unable to find the keys I am interested in logging in the 'dag' object. |
Beta Was this translation helpful? Give feedback.
-
|
Yes. That's deliberate change described in the changelog - one of the hallmark features of Airflow 3 where we isolated DB access from worker. Previously you could do more things with You should look at the changelog and see the recommendation and explanations in documentation. Including the advise to use Airflow's REST API to access the information about Dags, DagRuns and other airflow properties. This has been recommended for about 4 years now and the DB access was marked as not part of the publlc API since generally the beginning of Airflow 2 - Airflow 3 now enforces it and does not allow direct database access. If you feel like some things (from the logical point of view) should be available via task-sdk and you would think that accessing it in your worker without having to use public REST API, I recommend you to open an issue explainig the use pattern you want to have, why you think it is a common pattern that others will want to use, and possibly look at task SDK and propose where and how it could be implemented. We are doing it already when some of the "often used" access methods were commonly used and are missing now - for example #53628 - and we might consider adding it (but it's not like to follow previous access pattern where you could directly access "Database ORM objects) - you need to explain what exactly you need to access (specific logic you want to use it for) and explain why current REST API is not enough (basically what makes you think that the useage is common enough and "task" bound - so that you think it shoudl be built-in). |
Beta Was this translation helpful? Give feedback.
-
|
I am having a similar issue too. I used The recommended pattern now is to use the REST API? Does this mean I need to set up API auth to get access to this info? Additionally, does that mean I need to have the API server running to run Looking at the available methods in the objects, I found that the DagRun is still accessible with the following code. Is this pattern OK to use, or is it expected to go away in future releases of Airflow 3? |
Beta Was this translation helpful? Give feedback.
-
|
can you please test on the latest RC #54124 there is fix for this #53058 |
Beta Was this translation helpful? Give feedback.
-
|
I'm running into similar issues - I have been using The above now gives me Is there a drop in replacement via Where can we find what each |
Beta Was this translation helpful? Give feedback.
-
Maybe in the Documentation ? Who knows. Also this is an open-source project run by volunteers, and if you need any information missing in docs - you can always look at the source code. Some users also decide to give back and if they find missing or imprecise, or difficult to find documentation, look for it (also in the code) and help the whole community and other users by contributing missing docs and links. Highly recommended as a thank you for the software that they get for free. BTW. We have 3500 contributors. Many of them users who contributed missing docs and generally - gave back. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
In the previous versions of airflow I was able to get the
dag_runinformation from theon_success_callbackcontextwhen a DAG succeeded callback was triggered.Now, in Airflow 3, I see that the
dag_runis no longer populated in the callbackcontext. In my opinion this is a bug, also it is inconsistent with thetaskscallbacks as IT IS populated there.I read the documentation about callbacks here and it points to this the
contexttemplate variables which have thedag_run. Also the code here shows thedag_runso I cannot understand why it is not being populated.The fix seems to be a matter of adding
dag_run: self,here.In order to reproduce the issue, I created this DAG which prints the keys of the
contextfor DAG and tasks callbacks:The output of running this DAG shows that for the DAG callback the
dag_runis not present:The context for DAG callbacks has only these keys:
For the task callback we see the following keys:
And it has the
dag_runas well:So there is a massive difference in the information loaded in the
contextfor the task callbacks vs the DAG callback. Is this expected or is it a bug? As I said it seems to be a bug.Thanks,
Fede
Beta Was this translation helpful? Give feedback.
All reactions