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/06/22 00:18:28 UTC

[GitHub] [airflow] ejk43 opened a new pull request, #24592: Move fallible ti.task.dag assignment back inside try/except block (#24533)

ejk43 opened a new pull request, #24592:
URL: https://github.com/apache/airflow/pull/24592

   It looks like ti.task.dag was originally protected inside try/except, but was moved out at commit 7be87d
   
   This causes the "View Logs in Elasticsearch" option to crash in the Airflow UI
   
   related: #24533 


-- 
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 #24592: Move fallible ti.task.dag assignment back inside try/except block (#24533)

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

   I’m just going to merge this even without a second review since I wrote the original example.


-- 
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] ejk43 commented on a diff in pull request #24592: Move fallible ti.task.dag assignment back inside try/except block (#24533)

Posted by GitBox <gi...@apache.org>.
ejk43 commented on code in PR #24592:
URL: https://github.com/apache/airflow/pull/24592#discussion_r903724941


##########
airflow/providers/elasticsearch/log/es_task_handler.py:
##########
@@ -125,9 +125,9 @@ def _render_log_id(self, ti: TaskInstance, try_number: int) -> str:
             else:
                 log_id_template = self.log_id_template
 
-        dag = ti.task.dag
-        assert dag is not None  # For Mypy.
         try:
+            dag = ti.task.dag
+            assert dag is not None  # For Mypy.
             data_interval: Tuple[datetime, datetime] = dag.get_run_data_interval(dag_run)
         except AttributeError:  # ti.task is not always set.

Review Comment:
   Fair request -- updated



-- 
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] ejk43 commented on pull request #24592: Move fallible ti.task.dag assignment back inside try/except block (#24533)

Posted by GitBox <gi...@apache.org>.
ejk43 commented on PR #24592:
URL: https://github.com/apache/airflow/pull/24592#issuecomment-1164415343

   Another good catch. Thanks for the review and commit, I appreciate the detail.
   
   What's the process to get this into main branch from here? Is anything else needed? (first time PR for me)


-- 
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 #24592: Move fallible ti.task.dag assignment back inside try/except block (#24533)

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

   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] uranusjr commented on a diff in pull request #24592: Move fallible ti.task.dag assignment back inside try/except block (#24533)

Posted by GitBox <gi...@apache.org>.
uranusjr commented on code in PR #24592:
URL: https://github.com/apache/airflow/pull/24592#discussion_r903276343


##########
airflow/providers/elasticsearch/log/es_task_handler.py:
##########
@@ -125,9 +125,9 @@ def _render_log_id(self, ti: TaskInstance, try_number: int) -> str:
             else:
                 log_id_template = self.log_id_template
 
-        dag = ti.task.dag
-        assert dag is not None  # For Mypy.
         try:
+            dag = ti.task.dag
+            assert dag is not None  # For Mypy.
             data_interval: Tuple[datetime, datetime] = dag.get_run_data_interval(dag_run)
         except AttributeError:  # ti.task is not always set.

Review Comment:
   Judging from the comment on the `except` clause, this should be
   
   ```python
   try:
       dag = ti.task.dag
   except AttributeError:  # ti.task is not always set.
       ...
   else:
       assert dag is not None  # For Mypy.
       data_interval: Tuple[datetime, datetime] = dag.get_run_data_interval(dag_run)
   ```
   
   instead.



-- 
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 #24592: Move fallible ti.task.dag assignment back inside try/except block (#24533)

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

   We generally need two committer reviews to merge a PR, so let’s wait for 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] boring-cyborg[bot] commented on pull request #24592: Move fallible ti.task.dag assignment back inside try/except block (#24533)

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

   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] uranusjr merged pull request #24592: Move fallible ti.task.dag assignment back inside try/except block (#24533)

Posted by GitBox <gi...@apache.org>.
uranusjr merged PR #24592:
URL: https://github.com/apache/airflow/pull/24592


-- 
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 diff in pull request #24592: Move fallible ti.task.dag assignment back inside try/except block (#24533)

Posted by GitBox <gi...@apache.org>.
uranusjr commented on code in PR #24592:
URL: https://github.com/apache/airflow/pull/24592#discussion_r903276343


##########
airflow/providers/elasticsearch/log/es_task_handler.py:
##########
@@ -125,9 +125,9 @@ def _render_log_id(self, ti: TaskInstance, try_number: int) -> str:
             else:
                 log_id_template = self.log_id_template
 
-        dag = ti.task.dag
-        assert dag is not None  # For Mypy.
         try:
+            dag = ti.task.dag
+            assert dag is not None  # For Mypy.
             data_interval: Tuple[datetime, datetime] = dag.get_run_data_interval(dag_run)
         except AttributeError:  # ti.task is not always set.

Review Comment:
   Judging from the comment on the `except` clause, this should be
   
   ```python
   try:
       dag = ti.task.dag
   except AttributeError:  # ti.task is not always set.
       data_interval: Tuple[datetime, datetime] = (dag_run.data_interval_start, dag_run.data_interval_end)
   else:
       assert dag is not None  # For Mypy.
       data_interval = dag.get_run_data_interval(dag_run)
   ```
   
   instead.



-- 
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 #24592: Move fallible ti.task.dag assignment back inside try/except block (#24533)

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

   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] uranusjr commented on a diff in pull request #24592: Move fallible ti.task.dag assignment back inside try/except block (#24533)

Posted by GitBox <gi...@apache.org>.
uranusjr commented on code in PR #24592:
URL: https://github.com/apache/airflow/pull/24592#discussion_r904521923


##########
airflow/providers/elasticsearch/log/es_task_handler.py:
##########
@@ -125,12 +125,13 @@ def _render_log_id(self, ti: TaskInstance, try_number: int) -> str:
             else:
                 log_id_template = self.log_id_template
 
-        dag = ti.task.dag
-        assert dag is not None  # For Mypy.
         try:
-            data_interval: Tuple[datetime, datetime] = dag.get_run_data_interval(dag_run)
+            dag = ti.task.dag
         except AttributeError:  # ti.task is not always set.
             data_interval = (dag_run.data_interval_start, dag_run.data_interval_end)
+        else:
+            assert dag is not None  # For Mypy.
+            data_interval: Tuple[datetime, datetime] = dag.get_run_data_interval(dag_run)

Review Comment:
   ```suggestion
               data_interval = dag.get_run_data_interval(dag_run)
   ```
   
   I _think_ this can be removed now?



##########
airflow/utils/log/file_task_handler.py:
##########
@@ -93,12 +93,13 @@ def _render_filename(self, ti: "TaskInstance", try_number: int) -> str:
             context["try_number"] = try_number
             return render_template_to_string(jinja_tpl, context)
         elif str_tpl:
-            dag = ti.task.dag
-            assert dag is not None  # For Mypy.
             try:
-                data_interval: Tuple[datetime, datetime] = dag.get_run_data_interval(dag_run)
+                dag = ti.task.dag
             except AttributeError:  # ti.task is not always set.
                 data_interval = (dag_run.data_interval_start, dag_run.data_interval_end)
+            else:
+                assert dag is not None  # For Mypy.
+                data_interval: Tuple[datetime, datetime] = dag.get_run_data_interval(dag_run)

Review Comment:
   ```suggestion
                   data_interval = dag.get_run_data_interval(dag_run)
   ```



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