You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/03/09 10:17:42 UTC

[GitHub] [airflow] talnagar opened a new pull request #21851: added an option for run id in the ui trigger screen

talnagar opened a new pull request #21851:
URL: https://github.com/apache/airflow/pull/21851


   Added an option for custom run_id in the trigger dag screen.
   this option was already supported in the API.
   This commit includes:
   
   -  changes to the static template of the trigger screen
   - extraction of the run_id in the views.py
   - changes to models/dagrun.py - filter dag runs by run_id if exists or execution date 
   - unittest for: triggering dagrun with and without run_id, handling duplicate run_id 
   
   closes: #21336 
   
   Before:
   ![image](https://user-images.githubusercontent.com/7373236/156122454-aafbfa4b-1c3e-4321-857d-0dcacc826669.png)
   
   After:
   ![image](https://user-images.githubusercontent.com/7373236/156122338-717bbf97-0acb-46b9-b635-a68f09dccc63.png)
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ashb commented on pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
ashb commented on pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#issuecomment-1054395698


   Thanks for the PR!
   
   When making UI changes it is helpful to the reviewers if you include before and after screenshots.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] talnagar closed pull request #21851: add an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
talnagar closed pull request #21851:
URL: https://github.com/apache/airflow/pull/21851


   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] talnagar commented on pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
talnagar commented on pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#issuecomment-1059953168


   @bbovenzi I am trying to reproduce this error and write a unittest for it. 
   When I trigger tasks with duplicates in my local env I see the issue is handled and an error msg is shown:
   ![image](https://user-images.githubusercontent.com/7373236/156922949-7dc7a0fd-7699-4307-9f3f-600e7294bbfb.png)
   
   can you please write how did you produce this error?


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] talnagar edited a comment on pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
talnagar edited a comment on pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#issuecomment-1055137590


   > 
   
   thanks for the feedback, I added the screen shots to the PR. 
   I tried to use the same css classes I saw on other templates but wasn't sure if there is some tests that I need to do for different screen types/resolutions? 


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] talnagar commented on pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
talnagar commented on pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#issuecomment-1061576612


   @bbovenzi @uranusjr I just committed updates to the code:
   - moved dag filtration to model now using sqlalchemy. 
   - added a unittest for checking handling of duplicate run_id. 
   I would appreciate your feedback. 


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] talnagar commented on a change in pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
talnagar commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r820232142



##########
File path: airflow/www/views.py
##########
@@ -1838,10 +1839,15 @@ def trigger(self, session=None):
                 form=form,
                 is_dag_run_conf_overrides_params=is_dag_run_conf_overrides_params,
             )
-
-        dr = DagRun.find(dag_id=dag_id, execution_date=execution_date, run_type=DagRunType.MANUAL)
+        # if run_id is not None, filter dag runs based on run id and ignore execution date
+        dr = DagRun.find(
+            dag_id=dag_id,
+            run_type=DagRunType.MANUAL,
+            run_id=run_id,
+            execution_date=execution_date if run_id is None else None,

Review comment:
        DagRun.find() uses sqlalchemy if I understand it correctly:
   https://github.com/apache/airflow/blob/2157787c77b0afa1eda7099849c18ace12908b98/airflow/models/dagrun.py#L305
   I can change it to something like this but it may be a little too verbose: 
   ```
    elif run_id is not None or execution_date is not None:
               qry = qry.filter((cls.run_id == run_id) | (cls.execution_date == execution_date))
           elif execution_date is not None and run_id is None:
               qry = qry.filter(cls.execution_date == execution_date)
           elif run_id is not None and execution_date is None:
               qry = qry.filter(cls.run_id == run_id)
   ```




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] talnagar commented on a change in pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
talnagar commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r820232142



##########
File path: airflow/www/views.py
##########
@@ -1838,10 +1839,15 @@ def trigger(self, session=None):
                 form=form,
                 is_dag_run_conf_overrides_params=is_dag_run_conf_overrides_params,
             )
-
-        dr = DagRun.find(dag_id=dag_id, execution_date=execution_date, run_type=DagRunType.MANUAL)
+        # if run_id is not None, filter dag runs based on run id and ignore execution date
+        dr = DagRun.find(
+            dag_id=dag_id,
+            run_type=DagRunType.MANUAL,
+            run_id=run_id,
+            execution_date=execution_date if run_id is None else None,

Review comment:
       can you point me to a code snippet using SQLAlchemy? 




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] talnagar commented on pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
talnagar commented on pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#issuecomment-1063806085


   @uranusjr not sure I understand what you mean. add a separate function in models/dagrun.py to look for duplicate run ids instead of using the existing find?


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] talnagar commented on a change in pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
talnagar commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r817392507



##########
File path: airflow/www/templates/airflow/trigger.html
##########
@@ -35,15 +35,20 @@ <h2>Trigger DAG: {{ dag_id }}</h2>
     <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
     <input type="hidden" name="dag_id" value="{{ dag_id }}">
     <input type="hidden" name="origin" value="{{ origin }}">
-  <div class="form-group">
+    <div class="form-group">
       <label class="sr-only" for="execution_date">Logical date</label>
       <div class="input-group">
         {{ form.execution_date(class_="form-control", disabled=False) }}
       </div>
     </div>
-
+    <div class="form-group row">
+      <div class="col-md-2">
+        <label for="run_id">Run id (optional)</label>

Review comment:
       sure




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] talnagar commented on a change in pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
talnagar commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r820232142



##########
File path: airflow/www/views.py
##########
@@ -1838,10 +1839,15 @@ def trigger(self, session=None):
                 form=form,
                 is_dag_run_conf_overrides_params=is_dag_run_conf_overrides_params,
             )
-
-        dr = DagRun.find(dag_id=dag_id, execution_date=execution_date, run_type=DagRunType.MANUAL)
+        # if run_id is not None, filter dag runs based on run id and ignore execution date
+        dr = DagRun.find(
+            dag_id=dag_id,
+            run_type=DagRunType.MANUAL,
+            run_id=run_id,
+            execution_date=execution_date if run_id is None else None,

Review comment:
        DagRun.find() uses sqlalchemy if I understand it correctly:
   https://github.com/apache/airflow/blob/2157787c77b0afa1eda7099849c18ace12908b98/airflow/models/dagrun.py#L305
    Can you maybe suggest a change for  DagRun.find() that will support the 'OR' matches? (or point me to a similar code snippet). 




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
uranusjr commented on pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#issuecomment-1063789890


   Logic looks good to me, but can you change the code to _not_ use `DagRun.find()`, and leave the function unchanged? I don’t think this new logic is general enough that we should risk breaking backward compatibility. (Eventually I feel `DagRun.find()` should probably be removed entirely, but before that we would do better to avoid using it in new code.)


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] bbovenzi commented on pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
bbovenzi commented on pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#issuecomment-1060966793


   > can you please write how did you produce this error?
   
   Actually I'm not sure. I just tried again and the correct error was thrown.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] talnagar commented on a change in pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
talnagar commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r816497524



##########
File path: tests/www/views/test_views_trigger_dag.py
##########
@@ -214,3 +214,16 @@ def test_viewer_cant_trigger_dag(app):
         resp = client.get(url, follow_redirects=True)
         response_data = resp.data.decode()
         assert "Access is Denied" in response_data
+
+
+def test_trigger_dag_run_id(admin_client):
+    test_dag_id = "example_bash_operator"
+    test_run_id = "test_id"
+
+    admin_client.post(f'trigger?dag_id={test_dag_id}&run_id={test_run_id}')
+
+    with create_session() as session:
+        run = session.query(DagRun).filter(DagRun.dag_id == test_dag_id).first()
+    assert run is not None
+    assert run.run_type == DagRunType.MANUAL
+    assert run.run_id == test_run_id

Review comment:
       @uranusjr I didn't see a specific test for it, the other tests are for specific use cases like testing dag_params_conf and different tests for execution dates. I can make this test parameterized and check the outcome with or without run_id. 




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] talnagar commented on a change in pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
talnagar commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r816497524



##########
File path: tests/www/views/test_views_trigger_dag.py
##########
@@ -214,3 +214,16 @@ def test_viewer_cant_trigger_dag(app):
         resp = client.get(url, follow_redirects=True)
         response_data = resp.data.decode()
         assert "Access is Denied" in response_data
+
+
+def test_trigger_dag_run_id(admin_client):
+    test_dag_id = "example_bash_operator"
+    test_run_id = "test_id"
+
+    admin_client.post(f'trigger?dag_id={test_dag_id}&run_id={test_run_id}')
+
+    with create_session() as session:
+        run = session.query(DagRun).filter(DagRun.dag_id == test_dag_id).first()
+    assert run is not None
+    assert run.run_type == DagRunType.MANUAL
+    assert run.run_id == test_run_id

Review comment:
       @uranusjr I see a similar test for testing the trigger button but it's marked as @pytest.mark.quarantined. 
   Any idea why? https://github.com/apache/airflow/blob/4e9e12adbddc6e73d571fa38aeba6932d32e6fb3/tests/www/views/test_views_trigger_dag.py#L47




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on pull request #21851: add an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
uranusjr commented on pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#issuecomment-1064024682


   Oh, I was thinking we don’t need to add a function and could just use SQLAlchemy directly in `trigger`. But `find_duplicate` is actually better, nice find! I did not even know it 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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on a change in pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r819049649



##########
File path: airflow/www/views.py
##########
@@ -1838,10 +1839,15 @@ def trigger(self, session=None):
                 form=form,
                 is_dag_run_conf_overrides_params=is_dag_run_conf_overrides_params,
             )
-
-        dr = DagRun.find(dag_id=dag_id, execution_date=execution_date, run_type=DagRunType.MANUAL)
+        # if run_id is not None, filter dag runs based on run id and ignore execution date
+        dr = DagRun.find(
+            dag_id=dag_id,
+            run_type=DagRunType.MANUAL,
+            run_id=run_id,
+            execution_date=execution_date if run_id is None else None,

Review comment:
       I think we need to ditch `DagRun.find()` and use direct SQLAlchemy lookup to do an `OR` on `run_id` and `execution_date` matches.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on a change in pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r816022176



##########
File path: airflow/www/views.py
##########
@@ -1838,10 +1839,15 @@ def trigger(self, session=None):
                 form=form,
                 is_dag_run_conf_overrides_params=is_dag_run_conf_overrides_params,
             )
-
-        dr = DagRun.find(dag_id=dag_id, execution_date=execution_date, run_type=DagRunType.MANUAL)
+        # if run_id is not None, filter dag runs based on run id and ignore execution date
+        dr = DagRun.find(
+            dag_id=dag_id,
+            run_type=DagRunType.MANUAL,
+            run_id=run_id,
+            execution_date=execution_date if run_id is None else None,

Review comment:
       We still need to keep the `execution_date` clause when `run_id` is not None for now since two different run IDs with matching `execution_date` will fail.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] talnagar commented on a change in pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
talnagar commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r816495588



##########
File path: airflow/www/views.py
##########
@@ -1838,10 +1839,15 @@ def trigger(self, session=None):
                 form=form,
                 is_dag_run_conf_overrides_params=is_dag_run_conf_overrides_params,
             )
-
-        dr = DagRun.find(dag_id=dag_id, execution_date=execution_date, run_type=DagRunType.MANUAL)
+        # if run_id is not None, filter dag runs based on run id and ignore execution date
+        dr = DagRun.find(
+            dag_id=dag_id,
+            run_type=DagRunType.MANUAL,
+            run_id=run_id,
+            execution_date=execution_date if run_id is None else None,

Review comment:
       The reason I made this change is because the  DagRun.find (looking at existing runs and checking the run_id uniqueness) returns empty results when we send both run_id and execution_date since the combination is not found.
   
   what I tried to do here is:
   1. if there is a run_id - set execution_date to None and filter by the dag_id+run_id+run_type
   2. if run_id is None - filter by dag_id+execution_date+run_type
   
   




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] potiuk closed pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
potiuk closed pull request #21851:
URL: https://github.com/apache/airflow/pull/21851


   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] bbovenzi commented on pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
bbovenzi commented on pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#issuecomment-1058289957


   Can we handle duplicate `runId`s more elegantly?
   
   <img width="994" alt="Screen Shot 2022-03-03 at 12 19 34 PM" src="https://user-images.githubusercontent.com/4600967/156617333-c314cb7d-f2b3-4030-8707-99f8a078fe26.png">
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] boring-cyborg[bot] commented on pull request #21851: add an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#issuecomment-1068848147


   Awesome work, congrats on your first merged pull request!
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] bbovenzi edited a comment on pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
bbovenzi edited a comment on pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#issuecomment-1058289957


   ~~~Can we handle duplicate `runId`s more elegantly?~~~
   
   <img width="994" alt="Screen Shot 2022-03-03 at 12 19 34 PM" src="https://user-images.githubusercontent.com/4600967/156617333-c314cb7d-f2b3-4030-8707-99f8a078fe26.png">
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] talnagar edited a comment on pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
talnagar edited a comment on pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#issuecomment-1063806085


   @uranusjr not sure I understand what you mean. add a separate function in models/dagrun.py to look for duplicate run ids instead of using the existing find?
   I see there is a function for finding duplicates DagRun.find_duplicate():
   https://github.com/apache/airflow/blob/8c3f47948fb1679f0f9e617973236a2287f9bd51/airflow/models/dagrun.py#L365
   maybe I should switch to using it instead of DagRun.find()


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] bbovenzi commented on a change in pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
bbovenzi commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r816893213



##########
File path: airflow/www/templates/airflow/trigger.html
##########
@@ -35,15 +35,20 @@ <h2>Trigger DAG: {{ dag_id }}</h2>
     <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
     <input type="hidden" name="dag_id" value="{{ dag_id }}">
     <input type="hidden" name="origin" value="{{ origin }}">
-  <div class="form-group">
+    <div class="form-group">
       <label class="sr-only" for="execution_date">Logical date</label>
       <div class="input-group">
         {{ form.execution_date(class_="form-control", disabled=False) }}
       </div>
     </div>
-
+    <div class="form-group row">
+      <div class="col-md-2">
+        <label for="run_id">Run id (optional)</label>

Review comment:
       ```suggestion
           <label for="run_id">Run id (Optional)</label>
   ```
   
   Nitpick. But let's be consistent with the config below.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on a change in pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r816024093



##########
File path: tests/www/views/test_views_trigger_dag.py
##########
@@ -214,3 +214,16 @@ def test_viewer_cant_trigger_dag(app):
         resp = client.get(url, follow_redirects=True)
         response_data = resp.data.decode()
         assert "Access is Denied" in response_data
+
+
+def test_trigger_dag_run_id(admin_client):
+    test_dag_id = "example_bash_operator"
+    test_run_id = "test_id"
+
+    admin_client.post(f'trigger?dag_id={test_dag_id}&run_id={test_run_id}')
+
+    with create_session() as session:
+        run = session.query(DagRun).filter(DagRun.dag_id == test_dag_id).first()
+    assert run is not None
+    assert run.run_type == DagRunType.MANUAL
+    assert run.run_id == test_run_id

Review comment:
       Do we have a test for calling `trigger` _without_ `run_id`? If so, the two should be combined with `pytest.mark.parametrize`.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] talnagar commented on pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
talnagar commented on pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#issuecomment-1055137590


   > 
   
   thanks for the feedback, I added the screen shots to the PR.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] talnagar commented on a change in pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
talnagar commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r816634689



##########
File path: tests/www/views/test_views_trigger_dag.py
##########
@@ -214,3 +214,16 @@ def test_viewer_cant_trigger_dag(app):
         resp = client.get(url, follow_redirects=True)
         response_data = resp.data.decode()
         assert "Access is Denied" in response_data
+
+
+def test_trigger_dag_run_id(admin_client):
+    test_dag_id = "example_bash_operator"
+    test_run_id = "test_id"
+
+    admin_client.post(f'trigger?dag_id={test_dag_id}&run_id={test_run_id}')
+
+    with create_session() as session:
+        run = session.query(DagRun).filter(DagRun.dag_id == test_dag_id).first()
+    assert run is not None
+    assert run.run_type == DagRunType.MANUAL
+    assert run.run_id == test_run_id

Review comment:
       got it. 
   I removed the existing test from quarantine and parameterized it to check the use case of with and without run_id. 
   Hopefully it will be stable now. thanks :relaxed:




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#issuecomment-1061818378


   The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] bbovenzi edited a comment on pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
bbovenzi edited a comment on pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#issuecomment-1058289957


   ~~Can we handle duplicate `runId`s more elegantly?~~
   
   <img width="994" alt="Screen Shot 2022-03-03 at 12 19 34 PM" src="https://user-images.githubusercontent.com/4600967/156617333-c314cb7d-f2b3-4030-8707-99f8a078fe26.png">
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] potiuk merged pull request #21851: add an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
potiuk merged pull request #21851:
URL: https://github.com/apache/airflow/pull/21851


   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on a change in pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r816022176



##########
File path: airflow/www/views.py
##########
@@ -1838,10 +1839,15 @@ def trigger(self, session=None):
                 form=form,
                 is_dag_run_conf_overrides_params=is_dag_run_conf_overrides_params,
             )
-
-        dr = DagRun.find(dag_id=dag_id, execution_date=execution_date, run_type=DagRunType.MANUAL)
+        # if run_id is not None, filter dag runs based on run id and ignore execution date
+        dr = DagRun.find(
+            dag_id=dag_id,
+            run_type=DagRunType.MANUAL,
+            run_id=run_id,
+            execution_date=execution_date if run_id is None else None,

Review comment:
       We still need to keep the `execution_date` clause when `run_id` is not None for now since two different run IDs with matching `execution_date` will fail.
   
   ```suggestion
               execution_date=execution_date,
   ```




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on a change in pull request #21851: add an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r823688903



##########
File path: airflow/www/views.py
##########
@@ -1838,10 +1839,10 @@ def trigger(self, session=None):
                 form=form,
                 is_dag_run_conf_overrides_params=is_dag_run_conf_overrides_params,
             )
-
-        dr = DagRun.find(dag_id=dag_id, execution_date=execution_date, run_type=DagRunType.MANUAL)
+        # if run_id is not None, filter dag runs based on run id and ignore execution date
+        dr = DagRun.find_duplicate(dag_id=dag_id, run_id=run_id, execution_date=execution_date)
         if dr:
-            flash(f"This run_id {dr.run_id} already exists")
+            flash(f"The run_id {run_id} already exists", "error")

Review comment:
       ```suggestion
               flash(f"The run_id {dr.run_id} already exists", "error")
   ```
   
   I think this should use `dr.run_id` instead because `run_id` can be empty from the UI?




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] boring-cyborg[bot] commented on pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
boring-cyborg[bot] commented on pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#issuecomment-1053594666


   Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
   Here are some useful points:
   - Pay attention to the quality of your code (flake8, mypy and type annotations). Our [pre-commits]( https://github.com/apache/airflow/blob/main/STATIC_CODE_CHECKS.rst#prerequisites-for-pre-commit-hooks) will help you with that.
   - In case of a new feature add useful documentation (in docstrings or in `docs/` directory). Adding a new operator? Check this short [guide](https://github.com/apache/airflow/blob/main/docs/apache-airflow/howto/custom-operator.rst) Consider adding an example DAG that shows how users should use it.
   - Consider using [Breeze environment](https://github.com/apache/airflow/blob/main/BREEZE.rst) for testing locally, it’s a heavy docker but it ships with a working Airflow and a lot of integrations.
   - Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
   - Please follow [ASF Code of Conduct](https://www.apache.org/foundation/policies/conduct) for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
   - Be sure to read the [Airflow Coding style]( https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#coding-style-and-best-practices).
   Apache Airflow is a community-driven project and together we are making it better 🚀.
   In case of doubts contact the developers at:
   Mailing List: dev@airflow.apache.org
   Slack: https://s.apache.org/airflow-slack
   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ashb edited a comment on pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
ashb edited a comment on pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#issuecomment-1054395698


   Thanks for the PR!
   
   When making UI changes it is helpful to the reviewers if you include before and after screenshots in the PR description


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on a change in pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r816585835



##########
File path: tests/www/views/test_views_trigger_dag.py
##########
@@ -214,3 +214,16 @@ def test_viewer_cant_trigger_dag(app):
         resp = client.get(url, follow_redirects=True)
         response_data = resp.data.decode()
         assert "Access is Denied" in response_data
+
+
+def test_trigger_dag_run_id(admin_client):
+    test_dag_id = "example_bash_operator"
+    test_run_id = "test_id"
+
+    admin_client.post(f'trigger?dag_id={test_dag_id}&run_id={test_run_id}')
+
+    with create_session() as session:
+        run = session.query(DagRun).filter(DagRun.dag_id == test_dag_id).first()
+    assert run is not None
+    assert run.run_type == DagRunType.MANUAL
+    assert run.run_id == test_run_id

Review comment:
       It means at some point in the past this test was failing and we couldn’t figure out why. This should be the chance to un-quarantine it.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] bbovenzi commented on a change in pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
bbovenzi commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r816893213



##########
File path: airflow/www/templates/airflow/trigger.html
##########
@@ -35,15 +35,20 @@ <h2>Trigger DAG: {{ dag_id }}</h2>
     <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
     <input type="hidden" name="dag_id" value="{{ dag_id }}">
     <input type="hidden" name="origin" value="{{ origin }}">
-  <div class="form-group">
+    <div class="form-group">
       <label class="sr-only" for="execution_date">Logical date</label>
       <div class="input-group">
         {{ form.execution_date(class_="form-control", disabled=False) }}
       </div>
     </div>
-
+    <div class="form-group row">
+      <div class="col-md-2">
+        <label for="run_id">Run id (optional)</label>

Review comment:
       ```suggestion
           <label for="run_id">Run id (Optional)</label>
   ```
   
   Nitpick. But let's be consistent with the Configuration form group.




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] uranusjr commented on a change in pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
uranusjr commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r816023245



##########
File path: airflow/www/views.py
##########
@@ -1896,7 +1903,7 @@ def trigger(self, session=None):
                 is_dag_run_conf_overrides_params=is_dag_run_conf_overrides_params,
             )
 
-        flash(f"Triggered {dag_id}, it should start any moment now.")
+        flash(f"Triggered {dag_id},TALLL it should start any moment now.")

Review comment:
       Unintended?
   
   ```suggestion
           flash(f"Triggered {dag_id}, it should start any moment now.")
   ```




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] talnagar commented on a change in pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
talnagar commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r816497524



##########
File path: tests/www/views/test_views_trigger_dag.py
##########
@@ -214,3 +214,16 @@ def test_viewer_cant_trigger_dag(app):
         resp = client.get(url, follow_redirects=True)
         response_data = resp.data.decode()
         assert "Access is Denied" in response_data
+
+
+def test_trigger_dag_run_id(admin_client):
+    test_dag_id = "example_bash_operator"
+    test_run_id = "test_id"
+
+    admin_client.post(f'trigger?dag_id={test_dag_id}&run_id={test_run_id}')
+
+    with create_session() as session:
+        run = session.query(DagRun).filter(DagRun.dag_id == test_dag_id).first()
+    assert run is not None
+    assert run.run_type == DagRunType.MANUAL
+    assert run.run_id == test_run_id

Review comment:
       @uranusjr I see a similar test for testing the trigger button but it's marked as @pytest.mark.quarantined. 
   Any idea why? 




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] talnagar commented on a change in pull request #21851: added an option for run id in the ui trigger screen

Posted by GitBox <gi...@apache.org>.
talnagar commented on a change in pull request #21851:
URL: https://github.com/apache/airflow/pull/21851#discussion_r820232142



##########
File path: airflow/www/views.py
##########
@@ -1838,10 +1839,15 @@ def trigger(self, session=None):
                 form=form,
                 is_dag_run_conf_overrides_params=is_dag_run_conf_overrides_params,
             )
-
-        dr = DagRun.find(dag_id=dag_id, execution_date=execution_date, run_type=DagRunType.MANUAL)
+        # if run_id is not None, filter dag runs based on run id and ignore execution date
+        dr = DagRun.find(
+            dag_id=dag_id,
+            run_type=DagRunType.MANUAL,
+            run_id=run_id,
+            execution_date=execution_date if run_id is None else None,

Review comment:
        DagRun.find() uses sqlalchemy if I understand it correctly:
   https://github.com/apache/airflow/blob/2157787c77b0afa1eda7099849c18ace12908b98/airflow/models/dagrun.py#L305
   I can change it to something like this but it may be a little too verbose: 
   ```
   elif run_id is not None or execution_date is not None:
       qry = qry.filter((cls.run_id == run_id) | (cls.execution_date == execution_date))
   elif execution_date is not None and run_id is None:
       qry = qry.filter(cls.execution_date == execution_date)
   elif run_id is not None and execution_date is None:
       qry = qry.filter(cls.run_id == run_id)
   ```




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org