Repository navigation
Fix email_on_failure with render_template_as_native_obj - #22770
Conversation
uranusjr
left a comment
There was a problem hiding this comment.
Some nitpicks otherwise lgtm.
|
The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease. |
Co-authored-by: andyhuang <[email protected]>
Co-authored-by: Tzu-ping Chung <[email protected]>
9a1f125 to
073220f
Compare
|
|
||
| else: | ||
| jinja_env = self.task.get_template_env() | ||
| jinja_env = self.task.get_template_env(force_sandboxed=True) |
There was a problem hiding this comment.
i think you may need to update this operator to handle kwargs
also, this illustrates a backcompat issue if a user implemented this method (since it's a signature change).
if we wanted to be real careful we could inspect the signature before calling....
wdyt?
There was a problem hiding this comment.
Oh ugh that's going to make this approach hard/basically impossible. Nice catch @dstandish
There was a problem hiding this comment.
I think I lean toward this being "internal" to the task, but I'm not sure how others view it.
We could inspect, but emails would still fail even then. I wonder if we should instead release a new psrp provider that has a minimum core of 2.3.0. I guess the most 'flexible', ignoring the email issue, is to inspect in both so new providers still work on old core and vice versa.
There was a problem hiding this comment.
We could use dag.get_template_env(force_sandbox) instead of self in side the email rendering?
There was a problem hiding this comment.
Oh, good idea, it uses dag anyways! Let me try that.
blag
left a comment
There was a problem hiding this comment.
Besides @dstandish's questions, LGTM.
Co-authored-by: Daniel Standish <[email protected]>
| return self.task_id | ||
|
|
||
| def get_template_env(self) -> "jinja2.Environment": | ||
| def get_template_env(self, *, force_sandboxed: bool = False) -> "jinja2.Environment": |
There was a problem hiding this comment.
Think we should remove support for force_sandboxed here so we arent changing the signature of the method psrp is overriding?
There was a problem hiding this comment.
Doesn't do any harm since its an optional arg, but for the sake of a smaller diff, yes we could remove it.
There was a problem hiding this comment.
+1 to removing it since it’d make more obvious why we call the DAG’s get_template_env instead (so we can pass this option). It’d be nice to have a comment there describing why we don’t call the task’s get_template_env there.
There was a problem hiding this comment.
I pushed a commit for this (plus a small tweak for Mypy).
Also added comments on why we use the DAG level implementation instead of the task level one.
…2770) Co-authored-by: andyhuang <[email protected]> Co-authored-by: Tzu-ping Chung <[email protected]>
…2770) Co-authored-by: andyhuang <[email protected]> Co-authored-by: Tzu-ping Chung <[email protected]>
|
@jedcunningham |
As usual in open source - you can cherry-pick and apply it yourself. But we recommend to upgrade to 2.3 instead. Upgrading to latest released version is generally good thing to do. |
|
This is really the trade-off - either you take the burden of migration to what community maintain, or you take the maintenance burden yourself :). Choose one that is best for you. |
|
Agree :) |
|
Note that you can always manually add the patch—this one is simple enough I believe a simple |
|
And here's an example of how we patched another PR in a dockerfile RUN apt update && apt install -y patch patchutils
RUN set -ex; \
curl -o /tmp/kpo.patch https://patch-diff.githubusercontent.com/raw/apache/airflow/pull/24117.patch; \
cd /usr/local/lib/python3.9/site-packages/airflow; \
filterdiff -p1 -i 'airflow*' /tmp/kpo.patch | patch -u -p 2; \
rm /tmp/kpo.patch |
A Dag with render_template_as_native_obj=True made email_on_failure and email_on_retry alerts fail to send: the alert subject and body were evaluated into Python objects, which the email backend cannot send, and the resulting error was swallowed by the notification error handler, so the alert vanished without any signal to the operator. This was fixed once in apache#22770 and regressed when the alert path moved to SmtpNotifier in apache#57354, which dropped the only caller of force_sandboxed. Only the subject and body are forced to strings; the recipient fields keep rendering the way the Dag asks for, so a templated address list still resolves to a real list.
Co-authored-by: andyhuang [email protected]
Closes: #22152
Alternative of #22218, refactored to only change behavior when generating emails and including test coverage.
cc @andyfcx