Skip to content

Conversation

@prasad-madine
Copy link

@prasad-madine prasad-madine commented Mar 6, 2025

Description:

In the current UI, the DAGs list is sorted by default to display DAGs with the most recent DAG run first, achieved by sorting with -last_dag_run_start_date. However, this approach leads to an unintended consequence: DAGs that have never been run are displayed in reverse alphabetical order, which can be counterintuitive for users. Additionally, reversing the order of last_dag_run_start_date also affects the alphabetical order of DAGs.

backend part of: #46383

  • Add support for multi sort in the API

Test cases screenshot

image (1)

@boring-cyborg boring-cyborg bot added the area:API Airflow's REST/HTTP API label Mar 6, 2025
@boring-cyborg
Copy link

boring-cyborg bot commented Mar 6, 2025

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 pierrejeambrun changed the title fix:bug Add multisort to dags list request #46383 AIP-84 Add multisort to dags list request #46383 Mar 6, 2025
@pierrejeambrun pierrejeambrun added the AIP-84 Modern Rest API label Mar 6, 2025
@pierrejeambrun pierrejeambrun moved this to In Progress in AIP-84 MODERN REST API Mar 6, 2025
@pierrejeambrun pierrejeambrun added this to the Airflow 3.0.0 milestone Mar 6, 2025
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.

Nice, thanks for the pull request 🎉

I think we need:

  • To allow multi sorting on the get dags endpoint to solve the related issue.
  • Add tests for the get dags endpoint with multiple sort in the query and assert that it is doing what we expect.

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.

Nice, we need some tests too.

@pierrejeambrun
Copy link
Member

Don't hesitate to resolve comments that you have addressed. This will make the review easier, thanks.

@prasad-madine
Copy link
Author

Nice, we need some tests too.

Yes, currently working on that, will update the PR once it is done.
Thankyou

@prasad-madine
Copy link
Author

Don't hesitate to resolve comments that you have addressed. This will make the review easier, thanks.

I thought to do it after writing test cases.

@prasad-madine
Copy link
Author

Hi @pierrejeambrun , I have added few tests, COuld you please review it and let me know if any additional things to be required.
Thankyou

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.

Thanks for the PR. Looking good overall. One couple of comments only.

CI need fixing (tests, static check etc.), can you also rebase the branch solve conflicts.

@prasad-madine
Copy link
Author

@pierrejeambrun could you please review the PR, If any changes needs to be done, I'll address those.
Thankyou

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.

Thanks.

A few comments. Also the CI needs to be fixed:

self.to_replace = to_replace

def to_orm(self, select: Select) -> Select:
MAX_SORT_PARAMS = 5
Copy link
Member

Choose a reason for hiding this comment

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

I think the limit should be made greater.

We already have table with more than 5 columns and the UI could reach that pretty soon.

Going for 10 or 20 shouldn't hurt. (all our different db should be able to handle much more anyway)

Comment on lines +250 to +255
def inner(order_by: list[str] | str | None = Query(default)) -> SortParam:
if order_by is None:
order_by = [self.get_primary_key_string()]
elif isinstance(order_by, str):
order_by = [order_by]
return self.set_value(order_by)
Copy link
Member

@pierrejeambrun pierrejeambrun Mar 31, 2025

Choose a reason for hiding this comment

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

I'm not sure it's exactly equivalent. If there is no order_by query param specified, we shouldn't add any by default and let the query default order operate:

  • order_by = None => don't update the query at all and let the default ordering of the query operate.
  • order_by = [] or [""] -> fill with [primary_key_string] (or raise validation error)

Comment on lines +233 to +248
({"order_by": ["last_run_state", "dag_display_name"], "only_active": False}, 3, [DAG1_ID, DAG3_ID, DAG2_ID]),
({"order_by": ["-last_run_state", "dag_display_name"], "only_active": False}, 3, [DAG3_ID, DAG1_ID, DAG2_ID]),
({"order_by": ["last_run_start_date", "dag_display_name"], "only_active": False}, 3, [DAG1_ID, DAG3_ID, DAG2_ID]),
({"order_by": ["-last_run_start_date", "dag_display_name"], "only_active": False}, 3, [DAG3_ID, DAG1_ID, DAG2_ID]),
({"order_by": ["-dag_id", "dag_display_name"]}, 2, [DAG2_ID, DAG1_ID]),
({"order_by": ["dag_id", "dag_display_name"]}, 2, [DAG1_ID, DAG2_ID]),
({"order_by": ["dag_display_name", "dag_id"]}, 2, [DAG1_ID, DAG2_ID]),
({"order_by": ["last_run_state"], "only_active": False}, 3, [DAG1_ID, DAG3_ID, DAG2_ID]),
({"order_by": ["-last_run_state"], "only_active": False}, 3, [DAG3_ID, DAG1_ID, DAG2_ID]),
({"order_by": ["last_run_start_date"], "only_active": False}, 3, [DAG1_ID, DAG3_ID, DAG2_ID]),
({"order_by": ["-last_run_start_date"], "only_active": False}, 3, [DAG3_ID, DAG1_ID, DAG2_ID])
({"order_by": ["dag_display_name", "-next_dagrun"]}, 2, [DAG1_ID, DAG2_ID]),
({"order_by": ["last_run_state", "-dag_display_name", "dag_id"]}, 2, [DAG1_ID, DAG2_ID]),
({"order_by": ["-last_run_start_date", "dag_display_name", "next_dagrun", "dag_id"]}, 2, [ DAG1_ID, DAG2_ID]),
({"order_by": ["dag_display_name", "-last_run_state", "next_dagrun", "dag_id", "last_run_start_date"]}, 2, [DAG1_ID, DAG2_ID]),
Copy link
Member

Choose a reason for hiding this comment

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

We still need two tests with:

            ({"order_by": ["criteria_1", "criteria_2"]}, 2, [id1, id2, id3]),
            ({"order_by": ["criteria_1", "-criteria_2"]}, 2, [different sequence of id, proving that criteria_2 is being considerd]),

Comment on lines +253 to +254
elif isinstance(order_by, str):
order_by = [order_by]
Copy link
Member

Choose a reason for hiding this comment

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

This shouldn't be possible. FastAPI validation will prevent such wrong input and will do what's necessary to either get a list[str] or fail with a 422 validation error if not possible.

def inner(order_by: str = default or self.get_primary_key_string()) -> SortParam:
return self.set_value(self.get_primary_key_string() if order_by == "" else order_by)
def dynamic_depends(self, default: list[str] | None = None) -> Callable:
def inner(order_by: list[str] | str | None = Query(default)) -> SortParam:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def inner(order_by: list[str] | str | None = Query(default)) -> SortParam:
def inner(order_by: list[str] | None = Query(default)) -> SortParam:

@pierrejeambrun
Copy link
Member

@prasad-madine are you able to move forward, or do you need help ?

@prasad-madine
Copy link
Author

prasad-madine commented Apr 9, 2025

@prasad-madine are you able to move forward, or do you need help ?

@pierrejeambrun I've made changes, but facing issues in setup with latest code, I need to test it. I've also tried to setup application again. Need some help.

image
image

@pierrejeambrun
Copy link
Member

Make sure your images have been rebuilt to be up to date. (When you start breeze you should see a prompt asking if you want to rebuild or not, you need to answer yes to both of the prompt).

You can try in incognito mode in your browser. You might have some old cached version of the localstorage or cookies creating some problem.

Otherwise you can stop breeze then run breeze down and start breeze again.

If the issue persists you can try breeze cleanup.

@prasad-madine
Copy link
Author

Make sure your images have been rebuilt to be up to date. (When you start breeze you should see a prompt asking if you want to rebuild or not, you need to answer yes to both of the prompt).

You can try in incognito mode in your browser. You might have some old cached version of the localstorage or cookies creating some problem.

Otherwise you can stop breeze then run breeze down and start breeze again.

If the issue persists you can try breeze cleanup.

I've also tried incognito and also tried removing networks, volumes and docker images and rebuilt the application again, but still facing the same issue.

@pierrejeambrun
Copy link
Member

Something must be wrong, you can try on main. Be sure to rebuild images.

It looks like the connection is refused, the api-server is not reached. Also you can try with --dev-mode or without this flag.

@pierrejeambrun
Copy link
Member

That might be wrong on the auth manager asset compilation side for --dev-mode

@kaxil kaxil modified the milestones: Airflow 3.0.0, Airflow 3.1+ Apr 15, 2025
@pierrejeambrun
Copy link
Member

@prasad-madine did you manage to solve your local setup issue ?

@pierrejeambrun
Copy link
Member

@prasad-madine Any progress on that?

@prasad-madine
Copy link
Author

No @pierrejeambrun , still the issue with application setup is not resolved.

@pierrejeambrun
Copy link
Member

pierrejeambrun commented May 16, 2025

This does not happen on latest main. You can rebuild the images and start breeze again, you should be able to access the UI. Breeze documentation can be found here https://github.com/apache/airflow/tree/main/dev/breeze/doc.

You can run a breeze down then breeze cleanup to start over. That should definitely work on main branch. Also check that you don't have anything interfering in your files folder (env variables, entry point script etc...), default setup should work.

@github-actions
Copy link

github-actions bot commented Jul 1, 2025

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Jul 1, 2025
@pierrejeambrun
Copy link
Member

I am working on this, and will open a separate PR when it's ready

@pierrejeambrun
Copy link
Member

Closing in favor of #53408

@kaxil kaxil removed this from the Airflow 3.1.0 milestone Sep 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AIP-84 Modern Rest API area:API Airflow's REST/HTTP API stale Stale PRs per the .github/workflows/stale.yml policy file

Projects

No open projects
Status: In Progress

Development

Successfully merging this pull request may close these issues.

4 participants