Skip to content
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

Fix: render non-null falsy XCom entries correctly in UI #42199

Merged

Conversation

detvdl
Copy link
Contributor

@detvdl detvdl commented Sep 12, 2024

Fixed issues described in #42096, which were introduced in 563bc49

@boring-cyborg boring-cyborg bot added area:UI Related to UI/UX. For Frontend Developers. area:webserver Webserver related Issues labels Sep 12, 2024
@pierrejeambrun
Copy link
Member

pierrejeambrun commented Sep 12, 2024

Well funny enough I just left a comment here on a very related null/undefined check.

This is a mistake that is common in our codebase when we do ! and !! on falsy values unfortunately. We need to pay extra attention to that.

Also NaN is yet another case to handle (nullish coallescing will not handle that, we might need a common utility function).

Also do you mind explaining why we explicitely try to isNaN the value ? Coercion of isNaN is somewhat surprising, and I' m not sure what we are trying to actually check under the hood. Xcom values are bool, number, obj / null / undefined.

@detvdl
Copy link
Contributor Author

detvdl commented Sep 12, 2024

Also do you mind explaining why we explicitely try to isNaN the value ? Coercion of isNaN is somewhat surprising, and I' m not sure what we are trying to actually check under the hood. Xcom values are bool, number, obj / null / undefined.

isNaN returns True for both undefined or NaN so it was mostly a shortcut to check for both

Perhaps more idiomatic would be to use the nullish coalescing here to more explicitly catch the first 2 cases (null and undefined) and explicitly call isNan on the right hand side?

if (xcom.value ?? Number.isNaN(xcom.value))

From a quick peek at the code I figured both cases could be present exceptionally but I may be wrong, have only looked at the UI rendering for a few minutes.

I pragmatically just tackled this specific issue as soon as I saw it, and got a PR out not to forget 🙂

@pierrejeambrun
Copy link
Member

pierrejeambrun commented Sep 13, 2024

if (xcom.value ?? Number.isNaN(xcom.value))

In that case if we have a value we will enter the loop.

Maybe a simple:

xcom.value === undefined || xcom.value === null

We can always add the || Number.isNaN(xcom.value but I don't think we can actually have a NaN at this stage, but I'm not sure.

@detvdl detvdl force-pushed the fix/xcomEntry-false-bool-rendering branch from dacc91c to 6784a66 Compare September 13, 2024 07:27
@detvdl
Copy link
Contributor Author

detvdl commented Sep 13, 2024

if (xcom.value ?? Number.isNaN(xcom.value))

In that case if we have a value we will enter the loop.

Ah you're right, I hadn't stopped to think about that, good call!

I don't know about the NaN either, let me spend a little more time checking if it can happen and I will come back to this

After a quick peek, I can see that the XCom model value is serialized through SQLAlchemySchema's dump method or similar, which should never produce any value that is then further parsed back to NaN in the jsonParse method shown in 563bc49

There are ways to support NaN in those schemas for serialization (https://marshmallow.readthedocs.io/en/stable/upgrading.html#float-field-takes-a-new-allow-nan-parameter) but it's not the default, and nowhere in this codebase is it explicitly set (nor do I think Airflow uses a version of that dep which supports it)

So you're right @pierrejeambrun , just a plain undefined and null check should be fine and the most clear 🙂

fix: only treat null, undefined or NaN as NULL in XComEntry render

fix: use coalescing nullish check + isNaN

fix: only treat null/undefined as falsy when rendering XComEntry
@detvdl detvdl force-pushed the fix/xcomEntry-false-bool-rendering branch from 6784a66 to f610c19 Compare September 13, 2024 08:26
@pierrejeambrun
Copy link
Member

Great, thanks for the investigation @detvdl

@pierrejeambrun pierrejeambrun added this to the Airflow 2.10.2 milestone Sep 13, 2024
@pierrejeambrun pierrejeambrun merged commit ade9de1 into apache:main Sep 13, 2024
51 checks passed
pierrejeambrun pushed a commit to astronomer/airflow that referenced this pull request Sep 13, 2024
…che#42199)

fix: only treat null, undefined or NaN as NULL in XComEntry render

fix: use coalescing nullish check + isNaN

fix: only treat null/undefined as falsy when rendering XComEntry
(cherry picked from commit ade9de1)
@pierrejeambrun pierrejeambrun added type:bug-fix Changelog: Bug Fixes labels Sep 13, 2024
jscheffl pushed a commit that referenced this pull request Sep 13, 2024
) (#42213)

fix: only treat null, undefined or NaN as NULL in XComEntry render

fix: use coalescing nullish check + isNaN

fix: only treat null/undefined as falsy when rendering XComEntry
(cherry picked from commit ade9de1)

Co-authored-by: Detlev V. <detvdael.services@protonmail.com>
ephraimbuddy pushed a commit that referenced this pull request Sep 13, 2024
) (#42213)

fix: only treat null, undefined or NaN as NULL in XComEntry render

fix: use coalescing nullish check + isNaN

fix: only treat null/undefined as falsy when rendering XComEntry
(cherry picked from commit ade9de1)

Co-authored-by: Detlev V. <detvdael.services@protonmail.com>
joaopamaral pushed a commit to joaopamaral/airflow that referenced this pull request Oct 21, 2024
…che#42199)

fix: only treat null, undefined or NaN as NULL in XComEntry render

fix: use coalescing nullish check + isNaN

fix: only treat null/undefined as falsy when rendering XComEntry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:UI Related to UI/UX. For Frontend Developers. area:webserver Webserver related Issues type:bug-fix Changelog: Bug Fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants