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/10 12:54:19 UTC

[GitHub] [airflow] jyotsa09 opened a new issue #22144: Deleted task logs appended to new logs for scheduled runs

jyotsa09 opened a new issue #22144:
URL: https://github.com/apache/airflow/issues/22144


   ### Apache Airflow version
   
   main (development)
   
   ### What happened
   
   Deleted task logs appended to new logs for scheduled runs
   
   ### What you expected to happen
   
   Only new logs should display
   
   ### How to reproduce
   
   1. Triggered a scheduled run
   2. Once completed delete the dag from UI
   3. Triggered the same dag
   4. Then check logs
   
   ### Operating System
   
   Debian buster
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Astronomer
   
   ### Deployment details
   
   astro dev start
   
   ### Anything else
   
   ```
   from airflow import DAG
   
   from airflow.operators.python_operator import PythonOperator
   from airflow.operators.dummy_operator import DummyOperator
   from datetime import datetime, timedelta
   from airflow.utils.log.log_reader import TaskLogReader
   from pprint import pprint
   
   default_args = {
       "owner": "airflow",
       "depends_on_past": False,
       "start_date": datetime(2022, 3, 5),
       "email_on_failure": False,
       "email_on_retry": False,
       # "retries": 1,
       "retry_delay": timedelta(minutes=5),
   }
   
   
   def print_fun(message):
       """
       Insert arbitrary python function here
       """
       return message
   
   
   def read_logs(**context):
       dagrun = context["dag_run"]
       task_instance = dagrun.get_task_instance("python_function_hello")
       logs, _ = TaskLogReader().read_log_chunks(task_instance, 1, {"download_logs": True})
       assert "Returned value not shown" not in logs[0][0][1]
       assert "hello" in logs[0][0][1]
       task_instance = dagrun.get_task_instance("python_function_bye")
       logs, _ = TaskLogReader().read_log_chunks(task_instance, 1, {"download_logs": True})
       assert "Returned value not shown" in logs[0][0][1]
   
   
   dag = DAG(
       "example_python_operator_test",
       max_active_runs=3,
       catchup=True,
       schedule_interval="@daily",
       default_args=default_args,
       tags=["testim"],
   )
   
   
   with dag:
       start = DummyOperator(task_id="start")
   
       t1 = PythonOperator(
           task_id="python_function_hello",
           python_callable=print_fun,
           show_return_value_in_logs=True,
           op_args=["hello"],
           dag=dag,
       )
       t2 = PythonOperator(
           task_id="python_function_bye",
           python_callable=print_fun,
           show_return_value_in_logs=False,
           op_args=["bye"],
           dag=dag,
       )
       t3 = PythonOperator(
           task_id="function_read_logs",
           python_callable=read_logs,
           dag=dag,
       )
       start >> t1 >> t2 >> t3
   ```
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


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