gdavoian commented on PR #35546:
URL: https://github.com/apache/airflow/pull/35546#issuecomment-1876175035
@tlochner95 it's nice to hear that I'm not alone :)
First of all, I would join the items of your email list with commas, as it's
rendered as a string, not as a list (unless you set
`render_template_as_native_obj=True` on your DAG object):
```
'email': "{{ ','.join( var.json.EMAILS_TO_RECEIVE_FAILURE_ALERTS ) }}",
```
Secondly, the fact that `email` may be templated doesn't mean it's templated
by default. Unfortunately, that's not the case. So you must explicitly add
`email` to `template_fields` of your custom operators.
```
class MyOperator(BaseOperator):
template_fields = ('email',)
```
If you mostly use built-in or third-party operators, another option is to
implement a utility function that monkey-patches operators in the current scope
on the fly, which is exactly what we're doing. I can't share the source code,
but here's a hint on how you could implement it yourself: start with
`BaseOperator`, modify `template_fields` for all of its subclasses
(`BaseOperator.__subclasses__()`), and then recursively do the same for each
subclass, etc. Don't worry about infinite recursion; only the subclasses
defined in the imported modules will be visible through `__subclasses__()`, and
nothing more, typically a handful of classes in total. Finally, just call the
function once per DAG file and enjoy the convenience of enabled templating for
emails, which is disabled in Airflow by default.
--
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]