[jira] [Commented] (AIRFLOW-3123) Allow nested use of DAG as a context manager

2018-10-02 Thread Iuliia Volkova (JIRA)


[ 
https://issues.apache.org/jira/browse/AIRFLOW-3123?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16635103#comment-16635103
 ] 

Iuliia Volkova commented on AIRFLOW-3123:
-

[~newtonle], [~ashb], please don't forget to close the issue, PR was merged. 

> Allow nested use of  DAG as a context manager
> -
>
> Key: AIRFLOW-3123
> URL: https://issues.apache.org/jira/browse/AIRFLOW-3123
> Project: Apache Airflow
>  Issue Type: Bug
>  Components: DAG
>Reporter: Newton Le
>Assignee: Newton Le
>Priority: Major
>
> DAG context manager fails under some cases with nested contexts:
> {code:python}
> with DAG( ... ) as dag:
>   op1 = Operator()
>   with dag:
> op2 = Operator()
>   op3 = Operator
> {code}
> op3 will not continue to be assigned the original DAG after exiting the 
> nested context.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (AIRFLOW-3123) Allow nested use of DAG as a context manager

2018-09-28 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/AIRFLOW-3123?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16632125#comment-16632125
 ] 

ASF GitHub Bot commented on AIRFLOW-3123:
-

aoen closed pull request #3956: [AIRFLOW-3123] Allow nested use of  DAG as a 
context manager
URL: https://github.com/apache/incubator-airflow/pull/3956
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/models.py b/airflow/models.py
index a2de010c51..e4dffd3b47 100755
--- a/airflow/models.py
+++ b/airflow/models.py
@@ -3391,7 +3391,7 @@ def __init__(
 self.on_success_callback = on_success_callback
 self.on_failure_callback = on_failure_callback
 
-self._context_manager_set = False
+self._old_context_manager_dags = []
 
 self._comps = {
 'dag_id',
@@ -3440,16 +3440,13 @@ def __hash__(self):
 
 def __enter__(self):
 global _CONTEXT_MANAGER_DAG
-if not self._context_manager_set:
-self._old_context_manager_dag = _CONTEXT_MANAGER_DAG
-_CONTEXT_MANAGER_DAG = self
-self._context_manager_set = True
+self._old_context_manager_dags.append(_CONTEXT_MANAGER_DAG)
+_CONTEXT_MANAGER_DAG = self
 return self
 
 def __exit__(self, _type, _value, _tb):
 global _CONTEXT_MANAGER_DAG
-_CONTEXT_MANAGER_DAG = self._old_context_manager_dag
-self._context_manager_set = False
+_CONTEXT_MANAGER_DAG = self._old_context_manager_dags.pop()
 
 # /Context Manager --
 
diff --git a/tests/models.py b/tests/models.py
index 999b1be1bb..7e3c2929e0 100644
--- a/tests/models.py
+++ b/tests/models.py
@@ -141,11 +141,13 @@ def test_dag_as_context_manager(self):
 with dag:
 with dag:
 op7 = DummyOperator(task_id='op7')
-op8 = DummyOperator(task_id='op8')
-op8.dag = dag2
+op8 = DummyOperator(task_id='op8')
+op9 = DummyOperator(task_id='op8')
+op9.dag = dag2
 
 self.assertEqual(op7.dag, dag)
-self.assertEqual(op8.dag, dag2)
+self.assertEqual(op8.dag, dag)
+self.assertEqual(op9.dag, dag2)
 
 def test_dag_topological_sort(self):
 dag = DAG(


 


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Allow nested use of  DAG as a context manager
> -
>
> Key: AIRFLOW-3123
> URL: https://issues.apache.org/jira/browse/AIRFLOW-3123
> Project: Apache Airflow
>  Issue Type: Bug
>  Components: DAG
>Reporter: Newton Le
>Assignee: Newton Le
>Priority: Major
>
> DAG context manager fails under some cases with nested contexts:
> {code:python}
> with DAG( ... ) as dag:
>   op1 = Operator()
>   with dag:
> op2 = Operator()
>   op3 = Operator
> {code}
> op3 will not continue to be assigned the original DAG after exiting the 
> nested context.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)