-
Notifications
You must be signed in to change notification settings - Fork 14.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XCOM push ORA error code in OracleStoredProcedure #27319
Conversation
Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add unit test to cover this change
return hook.callproc(self.procedure, autocommit=True, parameters=self.parameters) | ||
except oracledb.DatabaseError as e: | ||
code, mesg = e.args[0].message[:-1].split(': ', 1) | ||
ti.xcom_push(key='ORA', value=str(code.split('-')[1])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check for self.do_xcom_push
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eladkal Do you mean checking whether self.do_xcom_push
is True
and only if so, then push to XCOM, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The flag exist so this could be user choice. The fact that some operators dont use it is not something we should encourage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eladkal fixed, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, there is a difference between data returned from an operator and meta-data describing the operator's execution. The self.do_xcom_push
controls the storing (pushing) of data returned by the logic of a given operator and not meta-data.
@eladkal What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider that not all users need this functionality. Why should we "spam" thier xcom table with data that has no value for them?
The use case of doing something in downstream task with error code of upstream task is not that common. at least from reviewing our issue tracker and questions on slack/other platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add unit test to cover this change
Let me ask, the tests have to be placed in airflow/tests/providers/oracle/operators/test_oracle.py
right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
Can you run pre-commit locally and fix linting errors, and add a test case for this? Some note in the operator docstring to explain what exactly is pushed to XCom would be nice as well; the various |
@uranusjr yes, sure, working on this |
okaaay... I was actually thinking of these alternatives and previuosly decided to split fully in the operator) But, okay I could accept that here I relied on too many tiny steps in which smth could be changed in future. Assume Oracle throws the following: Is that acceptable to just split the original output into two parts by The reasons I'd like to cut the message is that
|
@uranusjr doing this first time, I'm a bit stuck. Could you plz clarify, do these pre-commit scripts only work with Airflow Breeze docker env through .yaml scenario? |
You can accomplish the same thing using regex:
|
Yes, but above were the suggestion by @uranusjr not to split so much at all, no matter which way is used:
I prefer the way @bdsoha (to split). So if no objections to this I would commit |
If we are sure oracledb always emits errors in this format, splitting out the part before |
|
if code_match is not None: | ||
if self.do_xcom_push: | ||
if ti is not None: | ||
ti.xcom_push(key="ORA", value=code_match.group(1)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, this is cognitively complex.
if code_match is not None: | |
if self.do_xcom_push: | |
if ti is not None: | |
ti.xcom_push(key="ORA", value=code_match.group(1)) | |
if code_match and self.do_xcom_push and ti: | |
ti.xcom_push(key="ORA", value=code_match.group(1)) |
@bdsoha applied. Also I ran
Here is |
Tests are failing since airflow/tests/providers/oracle/operators/test_oracle.py Lines 27 to 35 in 47a2b9e
|
that's what I wrote above. |
@bdsoha Tests |
Needstests to be fixed. |
Motivation: #23787 ORA exit codes is controlled by the DB developer and could be a part of a dag logic. So in order to get access to these codes in dag, I propose an easy enhancement - push ORA exit code to XCOM when DatabaseError occurs. One file changed - providers/oracle/operators/oracle.py
Co-authored-by: Dov Benyomin Sohacheski <b@kloud.email>
#27319 (comment) Co-authored-by: Tzu-ping Chung <uranusjr@gmail.com>
Co-authored-by: Dov Benyomin Sohacheski <b@kloud.email>
Hi, I'm a bit stuck with the unit test and will update once it's resolved. |
OK. Cool |
Hi
Finally it's done. Please review. Files modified: In In |
Summary. ORA exit codes are controlled by the DB developer and could be a part of a dag logic. So in order to get access to these codes in dag, I propose an easy enhancement - push ORA exit code to XCOM when DatabaseError occurs.
One file changed - providers/oracle/operators/oracle.py
Motivation and detailed description - #23787 @potiuk