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 require_confirmation_dag_change #42063

Merged
merged 2 commits into from
Sep 12, 2024
Merged

Fix require_confirmation_dag_change #42063

merged 2 commits into from
Sep 12, 2024

Conversation

sowow359
Copy link
Contributor

@sowow359 sowow359 commented Sep 6, 2024

Currently require_confirmation_dag_change seems to have no effect on pause/resume switch, triggering the switch will cause confirmation window to show up regardless.

This is caused by JS type conversions. In current version with data-require-confirmation="{{ appbuilder.require_confirmation_dag_change }}" resulting value on JS side in onChange function has String type and does not automatically converts to boolean, which causes incorrect check:

...
const requireConfirmation = $input.data("require-confirmation");  // has String type, non-empty
if (requireConfirmation) { // evaluates to true on non-empty strings
...

Adding lower on jinja side does the trick and seems like simplest fix, resulting string successfully converts to boolean. After that confirmation window shows up only when passing True to require_confirmation_dag_change.


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an 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 a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in newsfragments.

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

boring-cyborg bot commented Sep 6, 2024

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 Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst)
Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@pierrejeambrun
Copy link
Member

pierrejeambrun commented Sep 9, 2024

Thank you for the pull request.

That seems a little odd that the normal string "Something" is considered a string (most things are then truthy), but casting it to lower somehow convert that to a boolean, I would think that this would remain a string something and the problem would stay.

I'll take a closer look tomorrow. I couldn't find the time today, I'll check it the next few days, thank you for your patience.

@pierrejeambrun
Copy link
Member

Ok, as I recall html attribute values are string, therefore, we end up with attribute='True' or attribute='False'.

Which does not work indeed, both are truthy.

Jquery has method is smart enought to convert a js string bool into an actual bool ('true', 'false'), but he does not recognize python bool of course i.e 'True' 'False' which remain strings. This is why casting to lower solves the issue.

The problem is that this is too implicit. People reading that code will not understand why it's here in a couple of weeks and will have to get back here. I would prefer something more explicit like we do with checked attribute. Also usually the convention is if a boolean attribute is present then it's true, otherwise it's false, independently of its value. For instance just checked is enough, no need to checked='true'.

I would only set the attribute if True like this:

     {{ "data-require-confirmation" if appbuilder.require_confirmation_dag_change else "" }}

Then adapt the jquery query to check if the attribute is set or not, something like:

  const requireConfirmation = $input.is("[data-require-confirmation]");

@sowow359 sowow359 requested a review from jscheffl as a code owner September 12, 2024 10:20
@sowow359 sowow359 changed the title Add 'lower' to require_confirmation_dag_change Fix require_confirmation_dag_change Sep 12, 2024
Copy link
Member

@pierrejeambrun pierrejeambrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good.

Working as expected ty.

@pierrejeambrun pierrejeambrun merged commit 9a1f9e9 into apache:main Sep 12, 2024
51 checks passed
Copy link

boring-cyborg bot commented Sep 12, 2024

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

@bbovenzi
Copy link
Contributor

We'll need to cherry pick this for v2-10-test.

@sowow359 sowow359 deleted the fix_require_confirmation_dag_change branch September 12, 2024 20:19
@pierrejeambrun
Copy link
Member

pierrejeambrun commented Sep 12, 2024

Yes! I’ll open the PR tomorrow

edit: #42211

@pierrejeambrun pierrejeambrun added this to the Airflow 2.10.2 milestone Sep 12, 2024
pierrejeambrun pushed a commit to astronomer/airflow that referenced this pull request Sep 13, 2024
* Add 'lower' to require_confirmation_dag_change

* Set input attribute only if require-confirmation is true

(cherry picked from commit 9a1f9e9)
bbovenzi pushed a commit that referenced this pull request Sep 13, 2024
* Add 'lower' to require_confirmation_dag_change

* Set input attribute only if require-confirmation is true

(cherry picked from commit 9a1f9e9)

Co-authored-by: Nikita <sowow359@ya.ru>
ephraimbuddy pushed a commit that referenced this pull request Sep 13, 2024
* Add 'lower' to require_confirmation_dag_change

* Set input attribute only if require-confirmation is true

(cherry picked from commit 9a1f9e9)

Co-authored-by: Nikita <sowow359@ya.ru>
joaopamaral pushed a commit to joaopamaral/airflow that referenced this pull request Oct 21, 2024
* Add 'lower' to require_confirmation_dag_change

* Set input attribute only if require-confirmation is true
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants