udsy19 opened a new pull request, #75590:
URL: https://github.com/apache/airflow/pull/75590
## Why
`get_python_source` (`airflow-core/src/airflow/utils/code_utils.py`) is
documented to get Python source "preventing exceptions", and the non-partial
path suppresses `TypeError` (falling back to `__call__` or a placeholder). But
the `functools.partial` branch calls `inspect.getsource(x.func)` **unguarded**:
```python
if isinstance(x, functools.partial):
source_code = inspect.getsource(x.func)
```
For a partial wrapping a builtin (`partial(len)`) or a callable object
(`partial(SomeCallable())`), `inspect.getsource` raises `TypeError`.
`serialization/serialized_objects.py` calls `get_python_source(var)` for any
callable, so such a value in serialized content crashes DAG serialization
instead of degrading gracefully.
## Fix
Resolve the partial to its wrapped callable and reuse the same logic:
```python
if isinstance(x, functools.partial):
return get_python_source(x.func)
```
A partial of a plain function behaves exactly as before (it resolves to the
same `getsource` call); partials of builtins/callable objects now return the
`__call__` source or the "No source code available" placeholder, and nested
partials are handled too.
## Tests
Adds `airflow-core/tests/unit/utils/test_code_utils.py` (no test existed for
this module), covering a partial of a function, of a builtin, and of a callable
object. Verified fail-on-revert: on upstream the builtin/callable-object
partials raise `TypeError`; with the fix all three pass and the
function-partial output is unchanged.
--
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]