-
Notifications
You must be signed in to change notification settings - Fork 16.4k
Allow sensors to return XCom values using tuple #20546
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
Conversation
|
I think this is pretty dangerous if you consider that sensor implementing this might (and likely will) be run with Airflow pre 2.3. It will work unexpectedly: As a result, such sensor will always succed if run on Airlfow 2.3. An interesting thing though, that it's not as bad. This will work fine if (and only if) we make sure that tuple is ONLY returned where the result is "True". And conicidentally - the "XCom" value is really ONLY needed when the returned value is True. There is really no point in storing XCom while the sensor is still running (see below). So in order to keep compatibiliyt, allowed return values shoudl be one of
That would be difficult to enforce though. But....... This leads me to conclusion that we do not need Tuple AT ALL :). If we assume that there is no need to store "", False, True or any other "un-truthy" value in XCom we could rather easily make backwards compatible implementation ny changing the contract of Then
This willl be backwards compatible - both existing Sensors will work in Airflow 2.3 and new sensors will work on Airlfow pre 2.3 (without storing XCom though). The only potential incompatibility is that truthy (non-Bool) poke output will also be stored as Xcom (but it is mis-use of sensor - it only supposed to have Bool output pre Airflow 2.3). And it has much better interface than the Tuple IMHO. |
|
Yeah I knew this approach is dangerous and that's why I also explored using a class here #20547. Using that class is more heavyhanded but it allows us to precisely know the implementer's intention. But your idea about "always returning the truthy value" as xcom is interesting. The the only problems are, what if you want to return something that doesn't behave correctly with respect to truthyness. In fact, pandas dataframes don't allow this! import pandas as pd
df = pd.DataFrame([1,2,3])
if df:
print('hi')The other (smaller) concern would be unnecessary xcom pushing when the user does not need xcom. |
|
BUT, it would be backwards compatible.... |
See #20547 -> I like this one much more as long as we add bool that will help those new Sensors to also work for Aiflow pre 2.3 properly. |
|
AAAAH NO. I am wrong. It's not going to work. When you run such new sensor on Airlfow 2.2, you will not have PokeReturnValue available! So it will not work. |
2e3343b to
deb361f
Compare
Historically sensors do not support returning XCom unless you override the `execute` method.
With this change we can optionally return an XCom value by returning one along with `True`
in a tuple e.g. `True, {"some": "information"}`
deb361f to
f233505
Compare
|
this pr taken over by @mingshi-wang in #20656 |
Historically sensors do not support returning XCom unless you override the
executemethod.With this change we can optionally return an XCom value by returning one along with
Truein a tuple e.g.
True, {"some": "information"}A key motivator for this PR is this other PR to add @task.sensor decorator. With the present PR merged, we can make it so the sensor decorator can return a tuple True, {"some": "info"} to push xcom.