henry3260 commented on code in PR #72036:
URL: https://github.com/apache/airflow/pull/72036#discussion_r4027870108


##########
airflow-core/src/airflow/cli/commands/team_command.py:
##########
@@ -303,3 +303,45 @@ def team_verify(args, *, session=NEW_SESSION):
         raise SystemExit(1)
 
     print("Verification succeeded.")
+
+
+@cli_utils.action_cli
+@providers_configuration_loaded
+@provide_session
+def team_inspect(args, *, session=NEW_SESSION):
+    """Inspect resources belonging to a team."""
+    team_name = _extract_team_name(args)

Review Comment:
   Should we check multi_team first?
   ```
   if not conf.getboolean("core", "multi_team"):
           print("Multi-team is not enabled.")
           return
   ```



##########
airflow-core/src/airflow/cli/commands/team_command.py:
##########
@@ -303,3 +303,45 @@ def team_verify(args, *, session=NEW_SESSION):
         raise SystemExit(1)
 
     print("Verification succeeded.")
+
+
+@cli_utils.action_cli
+@providers_configuration_loaded
+@provide_session
+def team_inspect(args, *, session=NEW_SESSION):
+    """Inspect resources belonging to a team."""
+    team_name = _extract_team_name(args)
+
+    team = session.scalar(select(Team).where(Team.name == team_name))
+    if team is None:
+        raise SystemExit(f"Team '{team_name}' does not exist")
+
+    bundle_names = session.scalars(
+        select(dag_bundle_team_association_table.c.dag_bundle_name)
+        .where(dag_bundle_team_association_table.c.team_name == team_name)
+        .order_by(dag_bundle_team_association_table.c.dag_bundle_name)
+    ).all()
+
+    pool_names = session.scalars(
+        select(Pool.pool).where(Pool.team_name == 
team_name).order_by(Pool.pool)
+    ).all()
+
+    connection_ids = session.scalars(
+        select(Connection.conn_id).where(Connection.team_name == 
team_name).order_by(Connection.conn_id)
+    ).all()
+
+    variable_keys = session.scalars(
+        select(Variable.key).where(Variable.team_name == 
team_name).order_by(Variable.key)
+    ).all()
+
+    AirflowConsole().print_as(
+        data=[team],
+        output=args.output,
+        mapper=lambda x: {
+            "name": x.name,
+            "dag_bundles": bundle_names,
+            "pools": pool_names,
+            "connections": connection_ids,
+            "variables": variable_keys,

Review Comment:
    `print_as` calls mapper once per element in data, so the mapper is expected 
to derive the whole row from x. Here only name does — the other four keys close 
over `bundle_names / pool_names / connection_ids / variable_keys`, which are 
computed once outside for a single team_name.
   
    It's correct today only because data has exactly one element. If data ever 
grows to more than one team, every row would silently repeat the first team's 
resources while name varies.
   
    Since there's only one row anyway, dropping the mapper and passing the dict 
directly would sidestep this  `print_as` accepts a dict sequence via 
is_data_sequence:
   
   
   ```
   AirflowConsole().print_as(
        data=[
            {
                "name": team.name,
                "dag_bundles": bundle_names,
                "pools": pool_names,
                "connections": connection_ids,
                "variables": variable_keys,
            }
        ],
        output=args.output,
    )
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to