Skip to content

Allow custom columns in cli dags list - #35250

Merged
potiuk merged 17 commits into
apache:mainfrom
jtmiclat:dag-list-additional-columns
Jan 7, 2024
Merged

potiuk merged 17 commits into
apache:mainfrom
jtmiclat:dag-list-additional-columns

Conversation

@jtmiclat

@jtmiclat jtmiclat commented Oct 29, 2023 •

Copy link
Copy Markdown
Contributor

This closes #34765

This adds an additional optional parameter columns to the cli command airflow dags list.

Examples:

root@2cce825aa9b1:/opt/airflow# airflow dags list
dag_id      | is_paused | fileloc             | owners
============+===========+=====================+========
my_dag_name | True      | /files/dags/test.py | airflow
root@2cce825aa9b1:/opt/airflow# airflow dags list --columns dag_id,last_parsed_time
dag_id      | last_parsed_time
============+=================================
my_dag_name | 2023-10-30T03:34:20.148064+00:00

Note: Will have a follow up pr to minimize database calls

@jtmiclat jtmiclat changed the title Allow additional columns in cliu dag list Allow additional columns in cli dag list Oct 29, 2023
@jtmiclat jtmiclat changed the title Allow additional columns in cli dag list Allow additional columns in cli dags list Oct 29, 2023
@eladkal eladkal added this to the Airflow 2.8.0 milestone Oct 29, 2023
@eladkal eladkal added the type:improvement Changelog: Improvements label Oct 29, 2023

@hussein-awala hussein-awala left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have two comments:

  • the additional-columns argument could help to close the issue, but we will always have the four columns (dag_id, filepath, owner and paused), but if we implement an argument for the columns to return and set it by default to these four columns, the user will be able to remove some of these columns from the returned result or add extra columns.
  • if the user provides a column name not found in the dag_details dict, the CLI will silently skip it, shall we validate the provided columns and raise an exception or at least a warning?

WDYT?

Comment thread tests/cli/commands/test_dag_command.py Resolved
@jtmiclat jtmiclat changed the title Allow additional columns in cli dags list Allow custom columns in cli dags list Oct 30, 2023
@jtmiclat

jtmiclat commented Oct 30, 2023 •

Copy link
Copy Markdown
Contributor Author

@hussein-awala Thank you for your comments!

I think both are good suggestions and pushed some changes to reflect them.

  1. I changed the parameter to just columns with default values
  2. I raised a system exit warning if there are invalid columns provided and ignores these columns

I just want to note the default behavior of airflow dag list in my implementation has changed a bit. Specifically the column names are now using the fields of the the dag schema rather than previous column names. Do you think we should alias these to the previous column names for backward compatibility?

Before

root@2cce825aa9b1:/opt/airflow# airflow dags list
dag_id      | filepath | owner   | paused
============+==========+=========+=======
my_dag_name | test.py  | airflow | True

After

root@2cce825aa9b1:/opt/airflow# airflow dags list
dag_id      | fileloc             | owners  | is_paused
============+=====================+=========+==========
my_dag_name | /files/dags/test.py | airflow | True

Comment thread airflow/cli/commands/dag_command.py Resolved
Comment thread tests/cli/commands/test_dag_command.py Resolved

@Lee-W Lee-W left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I left some nitpicks. But overall looks good to me 🙌

Comment thread airflow/cli/commands/dag_command.py Resolved
Comment thread airflow/cli/commands/dag_command.py Resolved
Comment thread airflow/cli/commands/dag_command.py Resolved
Comment thread airflow/cli/commands/dag_command.py Resolved
@jtmiclat
jtmiclat force-pushed the dag-list-additional-columns branch from 77c505c to 9bac6b8 Compare October 31, 2023 09:37
@jtmiclat

Copy link
Copy Markdown
Contributor Author

Merged the suggestions and fixed the tests !

@jtmiclat
jtmiclat force-pushed the dag-list-additional-columns branch from 9d3de81 to 9bac6b8 Compare November 2, 2023 08:59
@eladkal
eladkal force-pushed the dag-list-additional-columns branch from 04beaf5 to 4d93a68 Compare January 7, 2024 08:51
@eladkal
eladkal requested review from ephraimbuddy and potiuk January 7, 2024 08:52
@potiuk
potiuk merged commit da7de79 into apache:main Jan 7, 2024
@boring-cyborg

boring-cyborg Bot commented Jan 7, 2024

Copy link
Copy Markdown

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

@sidrahsayyad

Copy link
Copy Markdown

Hi @jtmiclat you've mentioned 'Note: Will have a follow up pr to minimize database calls', was that done as well ?

@jtmiclat

jtmiclat commented Jan 9, 2024

Copy link
Copy Markdown
Contributor Author

Hi @sidrahsayyad I haven't worked on it

)

def get_dag_detail(dag: DAG) -> dict:
dag_model = DagModel.get_dagmodel(dag.dag_id, session=session)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

get_dagmodel can return none. This introduced a bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:CLI type:improvement Changelog: Improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

need to run airflow cli command "airflow dags details" for multiple DAG IDs

7 participants