Repository: dbt-labs/dbt-core

Issue:
Include saved queries in `list` output
Right now `saved_queries` are not included in the output of `dbt list`. They should be.

Basic fix: https://github.com/dbt-labs/dbt-core/commit/d6e7cda5a16d3bb6f410252e13b63a9c69afc2b6

**Acceptance criteria:**
- `dbt list` includes resources with `NodeType.SavedQuery`


Discussion:

Resolving patch:
diff --git a/core/dbt/cli/params.py b/core/dbt/cli/params.py
--- a/core/dbt/cli/params.py
+++ b/core/dbt/cli/params.py
@@ -397,6 +397,7 @@
         [
             "metric",
             "semantic_model",
+            "saved_query",
             "source",
             "analysis",
             "model",
diff --git a/core/dbt/task/list.py b/core/dbt/task/list.py
--- a/core/dbt/task/list.py
+++ b/core/dbt/task/list.py
@@ -4,6 +4,7 @@
     Exposure,
     SourceDefinition,
     Metric,
+    SavedQuery,
     SemanticModel,
     UnitTestDefinition,
 )
@@ -31,6 +32,7 @@ class ListTask(GraphRunnableTask):
             NodeType.Source,
             NodeType.Exposure,
             NodeType.Metric,
+            NodeType.SavedQuery,
             NodeType.SemanticModel,
             NodeType.Unit,
         )
@@ -83,10 +85,12 @@ def _iterate_selected_nodes(self):
                 yield self.manifest.semantic_models[unique_id]
             elif unique_id in self.manifest.unit_tests:
                 yield self.manifest.unit_tests[unique_id]
+            elif unique_id in self.manifest.saved_queries:
+                yield self.manifest.saved_queries[unique_id]
             else:
                 raise DbtRuntimeError(
                     f'Got an unexpected result from node selection: "{unique_id}"'
-                    f"Expected a source or a node!"
+                    f"Listing this node type is not yet supported!"
                 )
 
     def generate_selectors(self):
@@ -106,6 +110,10 @@ def generate_selectors(self):
                 # metrics are searched for by pkg.metric_name
                 metric_selector = ".".join([node.package_name, node.name])
                 yield f"metric:{metric_selector}"
+            elif node.resource_type == NodeType.SavedQuery:
+                assert isinstance(node, SavedQuery)
+                saved_query_selector = ".".join([node.package_name, node.name])
+                yield f"saved_query:{saved_query_selector}"
             elif node.resource_type == NodeType.SemanticModel:
                 assert isinstance(node, SemanticModel)
                 semantic_model_selector = ".".join([node.package_name, node.name])


Test patch:
diff --git a/tests/functional/list/fixtures.py b/tests/functional/list/fixtures.py
--- a/tests/functional/list/fixtures.py
+++ b/tests/functional/list/fixtures.py
@@ -145,6 +145,24 @@
 """
 
 
+saved_queries__sq_yml = """
+saved_queries:
+  - name: my_saved_query
+    label: My Saved Query
+    query_params:
+        metrics:
+            - total_outer
+        group_by:
+            - "Dimension('my_entity__created_at')"
+    exports:
+        - name: my_export
+          config:
+            alias: my_export_alias
+            export_as: table
+            schema: my_export_schema_name
+"""
+
+
 @pytest.fixture(scope="class")
 def snapshots():
     return {"snapshot.sql": snapshots__snapshot_sql}
@@ -164,6 +182,7 @@ def models():
         "docs.md": models__docs_md,
         "outer.sql": models__outer_sql,
         "metricflow_time_spine.sql": models__metric_flow,
+        "sq.yml": saved_queries__sq_yml,
         "sm.yml": semantic_models__sm_yml,
         "m.yml": metrics__m_yml,
         "sub": {"inner.sql": models__sub__inner_sql},
@@ -195,6 +214,11 @@ def metrics():
     return {"m.yml": metrics__m_yml}
 
 
+@pytest.fixture(scope="class")
+def saved_queries():
+    return {"sq.yml": saved_queries__sq_yml}
+
+
 @pytest.fixture(scope="class")
 def project_files(
     project_root,
diff --git a/tests/functional/list/test_list.py b/tests/functional/list/test_list.py
--- a/tests/functional/list/test_list.py
+++ b/tests/functional/list/test_list.py
@@ -14,6 +14,7 @@
     analyses,
     semantic_models,
     metrics,
+    saved_queries,
     project_files,
 )
 
@@ -596,6 +597,7 @@ def expect_all_output(self):
             "test.t",
             "semantic_model:test.my_sm",
             "metric:test.total_outer",
+            "saved_query:test.my_saved_query",
         }
         # analyses have their type inserted into their fqn like tests
         expected_all = expected_default | {"test.analysis.a"}
@@ -626,6 +628,9 @@ def expect_select(self):
         results = self.run_dbt_ls(["--resource-type", "metric"])
         assert set(results) == {"metric:test.total_outer"}
 
+        results = self.run_dbt_ls(["--resource-type", "saved_query"])
+        assert set(results) == {"saved_query:test.my_saved_query"}
+
         results = self.run_dbt_ls(["--resource-type", "model", "--select", "outer+"])
         assert set(results) == {"test.outer", "test.sub.inner"}