kyleburke-meq commented on issue #40799:
URL: https://github.com/apache/airflow/issues/40799#issuecomment-2230864811
I would also love to see this feature. My current work around was to create
a custom decorator that expects a kwarg (in my case client_config) and use the
name in the config to pass to map_index_template at run time.
Example:
```python
def _eligibility_client_task(*task_args, **task_kwargs):
# Set default value for map_index_template if not provided
task_kwargs.setdefault('map_index_template', "{{ client_name }}")
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
# Dynamically find client_config in args or kwargs
sig = inspect.signature(func)
bound_args = sig.bind(*args, **kwargs)
bound_args.apply_defaults()
client_config = bound_args.arguments.get('client_config')
if client_config is None:
for arg in bound_args.arguments.values():
if isinstance(arg, dict) and 'client' in arg:
client_config = arg
break
if client_config:
# Assuming get_current_context is a function that retrieves
the current context
context = get_current_context()
context["client_name"] =
client_config['client']['client_name']
return func(*args, **kwargs)
# Apply the task decorator with the passed-through arguments and
keyword arguments
return task(*task_args, **task_kwargs)(wrapper)
return decorator
```
However this decorator is very specific and would prefer something that
works across the board rather than always searching for a kwarg.
--
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]