sseelmann opened a new issue, #41711:
URL: https://github.com/apache/airflow/issues/41711

   ### Apache Airflow version
   
   2.10.0
   
   ### If "Other Airflow 2 version" selected, which one?
   
   _No response_
   
   ### What happened?
   
   Tasks with `on_success_callback` where the actual callback function is 
wrapped with `functools.partial`, see reproduction steps below for an example.
   
   Task execution fails with
   
   ```
   [2024-08-24, 12:13:26 UTC] {standard_task_runner.py:124} ERROR - Failed to 
execute job 8 for task hello ('functools.partial' object has no attribute 
'__name__'; 931)
   Traceback (most recent call last):
     File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/task/task_runner/standard_task_runner.py",
 line 117, in _start_by_fork
       ret = args.func(args, dag=self.dag)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/cli/cli_config.py", 
line 49, in command
       return func(*args, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/cli.py", line 
115, in wrapper
       return f(*args, **kwargs)
              ^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/cli/commands/task_command.py",
 line 483, in task_run
       task_return_code = _run_task_by_selected_method(args, _dag, ti)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/cli/commands/task_command.py",
 line 256, in _run_task_by_selected_method
       return _run_raw_task(args, ti)
              ^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/cli/commands/task_command.py",
 line 341, in _run_raw_task
       return ti._run_raw_task(
              ^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/session.py", 
line 97, in wrapper
       return func(*args, session=session, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/models/taskinstance.py",
 line 2995, in _run_raw_task
       return _run_raw_task(
              ^^^^^^^^^^^^^^
     File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/models/taskinstance.py",
 line 358, in _run_raw_task
       _run_finished_callback(callbacks=ti.task.on_success_callback, 
context=context)
     File 
"/home/airflow/.local/lib/python3.12/site-packages/airflow/models/taskinstance.py",
 line 1554, in _run_finished_callback
       log.info("Executing %s callback", callback.__name__)
                                         ^^^^^^^^^^^^^^^^^
   AttributeError: 'functools.partial' object has no attribute '__name__'. Did 
you mean: '__ne__'?
   ```
   
   ### What you think should happen instead?
   
   _No response_
   
   ### How to reproduce
   
   ```
   from datetime import datetime
   from functools import partial
   from airflow import DAG
   from airflow.operators.bash import BashOperator
   
   
   def my_callback(context):
       print("partial_callback on success callbak")
   
   
   with DAG(dag_id="partial_callback", start_date=datetime(2022, 1, 1), 
schedule=None) as dag:
       hello = BashOperator(
           task_id="hello",
           bash_command="echo hello",
           on_success_callback=partial(my_callback),
       )
   
   ```
   
   ### Operating System
   
   Official container image
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Official Apache Airflow Helm Chart
   
   ### Deployment details
   
   _No response_
   
   ### Anything else?
   
   Might be related to this change: 
https://github.com/apache/airflow/pull/38892/files
   
   
   A workaround is to set the `__name__` property of the partial function:
   
   ```
   def _partial_with_name(func, arg):
       partial_with_name = partial(func, arg)
       partial_with_name.__name__ = arg.__name__ if hasattr(arg, "__name__") 
else "none"
       return partial_with_name
   ```
   
   ### 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: [email protected]

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

Reply via email to