tirkarthi commented on PR #27085:
URL: https://github.com/apache/airflow/pull/27085#issuecomment-1280766897

   I wrote a small script using ast module that might be helpful with 
`create_dagrun` related deprecation warnings.
   
   ```python
   import ast
   import sys
   
   
   class Visitor(ast.NodeVisitor):
       def __init__(self, code, filename):
           self.code = code
           self.filename = filename
   
       def visit_Call(self, node):
           if (
               getattr(node.func, "attr", None) == "create_dagrun"
               and any(keyword.arg == "execution_date" for keyword in 
node.keywords)
               and not any(keyword.arg == "data_interval" for keyword in 
node.keywords)
           ):
               if node.lineno != node.end_lineno:
                   line = "\n".join(
                       self.code.splitlines()[node.lineno - 1 : node.end_lineno 
- 1]
                   )
               else:
                   line = self.code.splitlines()[node.lineno - 1]
               print(self.filename, node.lineno, line)
           self.generic_visit(node)
   
   
   def main(filename):
       with open(filename) as f:
           code = f.read()
           Visitor(code=code, filename=filename).visit(ast.parse(code))
   
   
   if __name__ == "__main__":
       main(sys.argv[1])
   ```
   
   ```
   find tests/api/ -iname '*py' | xargs -I{} python 
../airflow_create_dagrun_warning.py {} 
   tests/api/common/test_mark_tasks.py 542         return 
self.dag1.create_dagrun(
               run_type=DagRunType.MANUAL, state=state, start_date=date, 
execution_date=date
   tests/api/common/test_mark_tasks.py 747         self.dag2.create_dagrun(
               run_type=DagRunType.MANUAL,
               state=State.FAILED,
               execution_date=self.execution_dates[0],
               session=session,
   tests/api/common/test_mark_tasks.py 753         dr2 = 
self.dag2.create_dagrun(
               run_type=DagRunType.MANUAL,
               state=State.FAILED,
               execution_date=self.execution_dates[1],
               session=session,
   tests/api/common/test_mark_tasks.py 759         self.dag2.create_dagrun(
               run_type=DagRunType.MANUAL,
               state=State.RUNNING,
               execution_date=self.execution_dates[2],
               session=session,
   ```


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to