FEAT : Add command to get DAG Details via CLI - #30432
Conversation
| for key, value in dag_detail.items(): | ||
| if isinstance(value, dict): | ||
| print(f"\t{key}:") | ||
| for subkey, subvalue in value.items(): | ||
| print(f"\t\t{subkey}: {subvalue}") | ||
| else: | ||
| print(f"\t{key}: {value}") |
There was a problem hiding this comment.
You are trying to implement a new logic for yaml output, and this doesn't support other types (json, table, plain).
Instead you can use AirflowConsole.print_as method, something like:
| for key, value in dag_detail.items(): | |
| if isinstance(value, dict): | |
| print(f"\t{key}:") | |
| for subkey, subvalue in value.items(): | |
| print(f"\t\t{subkey}: {subvalue}") | |
| else: | |
| print(f"\t{key}: {value}") | |
| AirflowConsole().print_as( | |
| data=[dag_detail], | |
| output=args.output, | |
| ) |
There was a problem hiding this comment.
Yep. All the CLI commands should use the same formatting options.
There was a problem hiding this comment.
Are you sure you want to do that @potiuk, @hussein-awala ? The default fallback when no --output option is provided is table -> so args.output becomes table by default, the SimpleTable isn't able to render such a large table properly due to the number of parameters and the length of these fields - most devices won't be able to display this output in a comprehensible way.
To standardise the approach, I've switched to AirflowConsole(), with a caveat that "table" isn't allowed as an output option - if it's received "yaml" output is displayed instead.
- Table Format
There was a problem hiding this comment.
Can you make a table support with swapped columns and rows ? I think that one will be much better.
There was a problem hiding this comment.
Ooo so essentially a transpose of the current table?
Let me know if I understand it currently, if initially the columns were scheduler_lock, is_active with Row1 being [], False -> now the rows will be scheduler_lock, is_active with Column1 having [], False?
Also, do we want this to be a new output type like --ttable? (Extra t for transposed)
There was a problem hiding this comment.
I like the idea of the transposed table, it's simple with no need to update the print_as method:
if args.output == "table":
data = [
{
"property_name": key,
"property_value": value
}
for key, value in dag_detail.items()
]
else:
data = [dag_detail]There was a problem hiding this comment.
As you can see in my previous comments, table & plain both formats were not rendered properly for the large number of attributes, so I've added checks for both of them.
There was a problem hiding this comment.
Nice. That's what I thought will be nicer :)
Co-authored-by: Hussein Awala <hussein@awala.fr>
| out = temp_stdout.getvalue() | ||
|
|
||
| # Check if DAG Details field are present | ||
| dag_details_fields = [ |
There was a problem hiding this comment.
This is not the right way. You should check attributes of the dag rather than list the fields by hand. If we ad a new field we wll 100% forget to add it here.
There was a problem hiding this comment.
Got it, I'll check all the attributes - don't get the "they should also likely be sorted part", do we want to display the command attributes in sorted order & test if the same order is maintained? Is there a reason behind doing this as it follows the same order as the REST Client response.
potiuk
left a comment
There was a problem hiding this comment.
Needs non-hardcoded attributes, they should be retrieved from dag_details.
There are a number of ways you can do it: https://stackoverflow.com/questions/2675028/list-attributes-of-an-object
Possibly you should filter some (those starting with _ and other common object attributes. They should also likely be sorted.
@potiuk On closer inspection, I found that listing attributes of the class directly isn't going to be a scalable solution either - we have to omit function names / other variable names in such a case as well - highly probable that someone adds a new function to the schema and doesn't add it to the test. |
|
LGTM Merge |
|
Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions. |
|
JUST in time for 2.6 |
--------- Co-authored-by: Hussein Awala <hussein@awala.fr> Co-authored-by: Hussein Awala <houssein.awala.96@gmail.com> (cherry picked from commit 7074167)
--------- Co-authored-by: Hussein Awala <hussein@awala.fr> Co-authored-by: Hussein Awala <houssein.awala.96@gmail.com>





This PR closes #30365
Problem Statement: At the moment, there is no support to view DAG Details via the Airflow CLI. The only support for viewing DAG Details is via the REST API at the endpoint: https://airflow.apache.org/api/v1/dags/{dag_id}/details
This new command in Airflow has the proposed format:

airflow dags details <dag-id>and returns all the details that are returned from the REST API as well. The terminal output currently looks like this: