Fix logging JDBC SQL error when task fails#21540
Conversation
o-nikolas
left a comment
There was a problem hiding this comment.
It looks like the exception that's happening during the handling of the first exception is actually Airflow filtering code (the secret masker specifically):
exception.args = (self.redact(v) for v in exception.args)
[2022-02-12, 09:27:16 UTC] {logging_mixin.py:115} WARNING - AttributeError: can't set attribute
I think this code should be patched to handle whatever edge case is occurring here, rather than the caller just catching the exception and logging it another way to work around it.
It looks like @potiuk was the last to touch the _redact_exception_with_context method, perhaps he has more context.
Yeah. I refectored a code that had literally this comment:
Apparently it was not. I think the right approach is to make the same try/except but in the place where redact is mdone @hubert-pietron Just find: and surround it with the: The problem is that in some exceptions the args are "read property" and you cannot replace them. |
|
Thanks for response! I pushed changes like you suggested @potiuk |
|
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. |
e97387f to
99347b3
Compare
Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
(cherry picked from commit bc1b422)
(cherry picked from commit bc1b422)
(cherry picked from commit bc1b422)
(cherry picked from commit bc1b422)
(cherry picked from commit bc1b422)
(cherry picked from commit bc1b422)
(cherry picked from commit bc1b422)
(cherry picked from commit bc1b422)
closes: #16295
closes: #18482
JDBC operator could not log errors when task failed. For specific type of error (jpype.java.sql.SQLException, jaydebeapi.DatabaseError, jaydebeapi.InterfaceError) this line
airflow/airflow/models/taskinstance.py
Line 1733 in 0a2d0d1
would produce AttributeError
Catching that error allow to see meaningful log when JDBC task fails.
example DAG
log after change
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.