dstandish commented on a change in pull request #5388: [AIRFLOW-4490] 
DagRun.conf returns empty dictionary by default
URL: https://github.com/apache/airflow/pull/5388#discussion_r292144810
 
 

 ##########
 File path: airflow/models/skipmixin.py
 ##########
 @@ -41,7 +41,7 @@ def skip(self, dag_run, execution_date, tasks, session=None):
         task_ids = [d.task_id for d in tasks]
         now = timezone.utcnow()
 
-        if dag_run:
+        if dag_run and dag_run.dag_id:
 
 Review comment:
   The idea here is that as long as submitting a dag run conf is supported we 
should make it easy to use it optionally in templates.
   
   I wanted a template like `{{ dag_run.conf.get('blah') or 'val' }}` to 
_always_ work.  But sometimes there is no dag run.  So in TI context, when 
there's no dag run, I added `DagRun()`, which has no dag_id by default.  But 
the skip mixing alters behavior based on presence of dag run obj in TI context.
   
   This is why I initially preferred the alternative PR 
https://github.com/apache/airflow/pull/5387 which adds `dag_run_conf` context 
variable instead of messing with `DagRun`.  But it seemed a little silly to add 
`dag_run_conf` when `dag_run.conf` is right there.
   
   Aside: Why is the skip mixing even checking for DagRun?  I don't know.  
Probably for testing I'd guess.  But skipping doesn't even make sense outside 
of the context of a dag run, so 🤷‍♀.
   
   **_Anyway,_** after further thought, I think it's _not good_ to provide an 
empty `DagRun()` for `dag_run` context variable when there is no dag run.  It 
should just be `None`.  And I will update this PR.  Then the above template 
example would still work whenever there is a DagRun (which is most of the 
time).  And for contrived situations like repl-testing of your templating you 
can manufacture a dag run.   
   
   Do you think that `dag_run_conf` is still worth adding though, so that there 
can be one variable we can use to safely check for a dag run conf variable -- 
no matter whether a dag run exists or whether a conf exists?
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to