Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Return upstream breaking entities for dependencies (#68282)

Riley Thompson21f043d697e1
diff --git a/e2e/support/helpers/e2e-data-studio-helpers.ts b/e2e/support/helpers/e2e-data-studio-helpers.ts
index 881ddec0b87..d9a16ad94f5 100644
--- a/e2e/support/helpers/e2e-data-studio-helpers.ts
+++ b/e2e/support/helpers/e2e-data-studio-helpers.ts
@@ -132,6 +132,7 @@ export const DataStudio = {
libraryPage().findAllByTestId("collection-name").contains(name),
},
Tasks: {
+ visitBrokenEntities: () => cy.visit("/data-studio/tasks/broken"),
visitUnreferencedEntities: () =>
cy.visit("/data-studio/tasks/unreferenced"),
list: () => cy.findByTestId("dependency-list"),
@@ -143,9 +144,13 @@ export const DataStudio = {
get: () => cy.findByTestId("dependency-list-sidebar"),
header: () => cy.findByTestId("dependency-list-sidebar-header"),
locationInfo: () => cy.findByRole("region", { name: "Location" }),
- errorInfo: (label: string) => cy.findByRole("region", { name: label }),
+ transformInfo: () => cy.findByRole("region", { name: "Transform" }),
+ missingColumnsInfo: () =>
+ cy.findByRole("region", { name: "Missing columns" }),
creationInfo: () =>
cy.findByRole("region", { name: "Creator and last editor" }),
+ brokenDependentsInfo: () =>
+ cy.findByRole("region", { name: "Broken dependents" }),
},
},
};
diff --git a/e2e/test/scenarios/dependencies/dependency-broken-list.cy.spec.ts b/e2e/test/scenarios/dependencies/dependency-broken-list.cy.spec.ts
new file mode 100644
index 00000000000..cd8bbf8c02d
--- /dev/null
+++ b/e2e/test/scenarios/dependencies/dependency-broken-list.cy.spec.ts
@@ -0,0 +1,541 @@
+import { WRITABLE_DB_ID } from "e2e/support/cypress_data";
+import { ADMIN_PERSONAL_COLLECTION_ID } from "e2e/support/cypress_sample_instance_data";
+import type { TransformId } from "metabase-types/api";
+
+const { H } = cy;
+
+const TABLE_NAME = "test_transform_table";
+const TABLE_DISPLAY_NAME = "Test Transform Table";
+const TABLE_TRANSFORM = "Test Transform";
+const TABLE_BASED_QUESTION_BROKEN_FIELD =
+ "Table-based question with broken field";
+const TABLE_BASED_QUESTION_BROKEN_EXPRESSION =
+ "Table-based question with broken expression";
+const TABLE_BASED_QUESTION_BROKEN_FILTER =
+ "Table-based question with broken filter";
+const TABLE_BASED_QUESTION_BROKEN_BREAKOUT =
+ "Table-based question with broken breakout";
+const TABLE_BASED_QUESTION_BROKEN_AGGREGATION =
+ "Table-based question with broken aggregation";
+const TABLE_BASED_QUESTION_BROKEN_EXPLICIT_JOIN =
+ "Table-based question with broken explicit join";
+const TABLE_BASED_QUESTION = "Table-based question";
+const QUESTION_BASED_QUESTION_BROKEN_FILTER =
+ "Question-based question with broken filter";
+const TABLE_BASED_MODEL = "Table-based model";
+const MODEL_BASED_MODEL_BROKEN_AGGREGATION =
+ "Model-based model with broken aggregation";
+
+const BROKEN_TABLE_DEPENDENCIES = [TABLE_DISPLAY_NAME];
+const BROKEN_TABLE_DEPENDENTS = [
+ TABLE_BASED_QUESTION_BROKEN_FIELD,
+ TABLE_BASED_QUESTION_BROKEN_EXPRESSION,
+ TABLE_BASED_QUESTION_BROKEN_FILTER,
+ TABLE_BASED_QUESTION_BROKEN_BREAKOUT,
+ TABLE_BASED_QUESTION_BROKEN_AGGREGATION,
+ TABLE_BASED_QUESTION_BROKEN_EXPLICIT_JOIN,
+];
+const BROKEN_QUESTION_DEPENDENCIES = [TABLE_BASED_QUESTION];
+const BROKEN_QUESTION_DEPENDENTS = [QUESTION_BASED_QUESTION_BROKEN_FILTER];
+const BROKEN_MODEL_DEPENDENCIES = [TABLE_BASED_MODEL];
+const BROKEN_MODEL_DEPENDENTS = [MODEL_BASED_MODEL_BROKEN_AGGREGATION];
+
+const BROKEN_DEPENDENCIES = [
+ ...BROKEN_TABLE_DEPENDENCIES,
+ ...BROKEN_QUESTION_DEPENDENCIES,
+ ...BROKEN_MODEL_DEPENDENCIES,
+];
+
+const BROKEN_DEPENDENCIES_SORTED_BY_NAME = [
+ TABLE_BASED_MODEL,
+ TABLE_BASED_QUESTION,
+ TABLE_DISPLAY_NAME,
+];
+
+const BROKEN_DEPENDENCIES_SORTED_BY_LOCATION = [
+ TABLE_BASED_QUESTION, // Bobby Tables's personal collection
+ TABLE_BASED_MODEL, // Our analytics
+ TABLE_DISPLAY_NAME, // Writable Postgres
+];
+
+const BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_ERRORS = [
+ TABLE_BASED_QUESTION, // 1 error: PRICE
+ TABLE_BASED_MODEL, // 1 error: AMOUNT
+ TABLE_DISPLAY_NAME, // 2 errors: SCORE, STATUS
+];
+
+const BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_WITH_ERRORS = [
+ TABLE_BASED_QUESTION, // 1 question
+ TABLE_BASED_MODEL, // 1 model
+ TABLE_DISPLAY_NAME, // 6 questions
+];
+
+const BROKEN_DEPENDENTS = [
+ ...BROKEN_TABLE_DEPENDENTS,
+ ...BROKEN_QUESTION_DEPENDENTS,
+ ...BROKEN_MODEL_DEPENDENTS,
+];
+
+describe("scenarios > dependencies > broken list", () => {
+ beforeEach(() => {
+ H.restore("postgres-writable");
+ cy.signInAsAdmin();
+ H.activateToken("bleeding-edge");
+ createContent();
+ });
+
+ afterEach(() => {
+ dropTransformTable();
+ });
+
+ describe("analysis", () => {
+ it("should show broken dependencies", () => {
+ H.DataStudio.Tasks.visitBrokenEntities();
+ checkList({
+ visibleEntities: BROKEN_DEPENDENCIES,
+ hiddenEntities: BROKEN_DEPENDENTS,
+ });
+ });
+ });
+
+ describe("sidebar", () => {
+ it("should show broken dependents", () => {
+ H.DataStudio.Tasks.visitBrokenEntities();
+
+ cy.log("table dependents");
+ H.DataStudio.Tasks.list().findByText(TABLE_DISPLAY_NAME).click();
+ checkSidebar({
+ entityName: TABLE_DISPLAY_NAME,
+ transformName: TABLE_TRANSFORM,
+ missingColumns: ["score", "status"],
+ brokenDependents: BROKEN_TABLE_DEPENDENTS,
+ });
+
+ cy.log("question dependents");
+ H.DataStudio.Tasks.list().findByText(TABLE_BASED_QUESTION).click();
+ checkSidebar({
+ entityName: TABLE_BASED_QUESTION,
+ missingColumns: ["PRICE"],
+ brokenDependents: BROKEN_QUESTION_DEPENDENTS,
+ });
+
+ cy.log("model dependents");
+ H.DataStudio.Tasks.list().findByText(TABLE_BASED_MODEL).click();
+ checkSidebar({
+ entityName: TABLE_BASED_MODEL,
+ missingColumns: ["AMOUNT"],
+ brokenDependents: BROKEN_MODEL_DEPENDENTS,
+ });
+ });
+ });
+
+ describe("search", () => {
+ it("should search for entities", () => {
+ H.DataStudio.Tasks.visitBrokenEntities();
+ H.DataStudio.Tasks.searchInput().type(TABLE_DISPLAY_NAME);
+ checkList({
+ visibleEntities: [TABLE_DISPLAY_NAME],
+ hiddenEntities: [TABLE_BASED_QUESTION, TABLE_BASED_MODEL],
+ });
+ });
+ });
+
+ describe("filtering", () => {
+ it("should filter entities by type", () => {
+ H.DataStudio.Tasks.visitBrokenEntities();
+ H.DataStudio.Tasks.filterButton().click();
+ H.popover().within(() => {
+ cy.findByText("Table").click();
+ cy.findByText("Question").click();
+ cy.findByText("Model").click();
+ });
+
+ cy.log("only tables");
+ H.popover().findByText("Table").click();
+ checkList({
+ visibleEntities: BROKEN_TABLE_DEPENDENCIES,
+ hiddenEntities: [
+ ...BROKEN_QUESTION_DEPENDENCIES,
+ ...BROKEN_MODEL_DEPENDENCIES,
+ ],
+ });
+
+ cy.log("only questions");
+ H.popover().within(() => {
+ cy.findByText("Table").click();
+ cy.findByText("Question").click();
+ });
+ checkList({
+ visibleEntities: BROKEN_QUESTION_DEPENDENCIES,
+ hiddenEntities: [
+ ...BROKEN_TABLE_DEPENDENCIES,
+ ...BROKEN_MODEL_DEPENDENCIES,
+ ],
+ });
+
+ cy.log("only models");
+ H.popover().within(() => {
+ cy.findByText("Question").click();
+ cy.findByText("Model").click();
+ });
+ checkList({
+ visibleEntities: BROKEN_MODEL_DEPENDENCIES,
+ hiddenEntities: [
+ ...BROKEN_TABLE_DEPENDENCIES,
+ ...BROKEN_QUESTION_DEPENDENCIES,
+ ],
+ });
+ });
+
+ it("should filter entities by location", () => {
+ H.DataStudio.Tasks.visitBrokenEntities();
+ H.DataStudio.Tasks.filterButton().click();
+ H.popover().within(() => {
+ cy.findByText("Include items in personal collections").click();
+ });
+ checkList({
+ visibleEntities: [
+ ...BROKEN_TABLE_DEPENDENCIES,
+ ...BROKEN_MODEL_DEPENDENCIES,
+ ],
+ hiddenEntities: BROKEN_QUESTION_DEPENDENCIES,
+ });
+ });
+ });
+
+ describe("sorting", () => {
+ it("should sort by name", () => {
+ H.DataStudio.Tasks.visitBrokenEntities();
+
+ cy.log("sorted by name by default");
+ checkListSorting({
+ visibleEntities: BROKEN_DEPENDENCIES_SORTED_BY_NAME,
+ });
+
+ cy.log("sorted by name ascending");
+ H.DataStudio.Tasks.list().findByText("Dependency").click();
+ checkListSorting({
+ visibleEntities: BROKEN_DEPENDENCIES_SORTED_BY_NAME,
+ });
+
+ cy.log("sorted by name descending");
+ H.DataStudio.Tasks.list().findByText("Dependency").click();
+ checkListSorting({
+ visibleEntities: [...BROKEN_DEPENDENCIES_SORTED_BY_NAME].reverse(),
+ });
+ });
+
+ it("should sort by location", () => {
+ H.DataStudio.Tasks.visitBrokenEntities();
+
+ cy.log("sorted by location ascending");
+ H.DataStudio.Tasks.list().findByText("Location").click();
+ checkListSorting({
+ visibleEntities: BROKEN_DEPENDENCIES_SORTED_BY_LOCATION,
+ });
+
+ cy.log("sorted by location descending");
+ H.DataStudio.Tasks.list().findByText("Location").click();
+ checkListSorting({
+ visibleEntities: [...BROKEN_DEPENDENCIES_SORTED_BY_LOCATION].reverse(),
+ });
+ });
+
+ it("should sort by dependents errors", () => {
+ H.DataStudio.Tasks.visitBrokenEntities();
+
+ cy.log("sorted by dependents errors ascending");
+ H.DataStudio.Tasks.list().findByText("Problems").click();
+ checkListSorting({
+ visibleEntities: [
+ ...BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_ERRORS,
+ ].reverse(),
+ });
+
+ cy.log("sorted by dependents errors descending");
+ H.DataStudio.Tasks.list().findByText("Problems").click();
+ checkListSorting({
+ visibleEntities: BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_ERRORS,
+ });
+ });
+
+ it("should sort by dependents with errors", () => {
+ H.DataStudio.Tasks.visitBrokenEntities();
+
+ cy.log("sorted by dependents with errors ascending");
+ H.DataStudio.Tasks.list().findByText("Broken dependents").click();
+ checkListSorting({
+ visibleEntities: [
+ ...BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_WITH_ERRORS,
+ ].reverse(),
+ });
+
+ cy.log("sorted by dependents with errors descending");
+ H.DataStudio.Tasks.list().findByText("Broken dependents").click();
+ checkListSorting({
+ visibleEntities: BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_WITH_ERRORS,
+ });
+ });
+ });
+});
+
+function createContent() {
+ createTransform();
+ createTableContent();
+ createQuestionContent();
+ createModelContent();
+ breakTransform();
+}
+
+function dropTransformTable() {
+ cy.get<TransformId>("@transformId").then((transformId) => {
+ cy.request("DELETE", `/api/ee/transform/${transformId}/table`);
+ });
+}
+
+function createTransform() {
+ H.createTransform(
+ {
+ name: TABLE_TRANSFORM,
+ source: {
+ type: "query",
+ query: {
+ type: "native",
+ database: WRITABLE_DB_ID,
+ native: {
+ query: "SELECT 1 as score, 'active' as status",
+ },
+ },
+ },
+ target: {
+ type: "table",
+ database: WRITABLE_DB_ID,
+ schema: "public",
+ name: TABLE_NAME,
+ },
+ },
+ { wrapId: true },
+ );
+ cy.get<TransformId>("@transformId").then((transformId) => {
+ H.runTransform(transformId);
+ H.waitForTransformRuns(
+ (runs) =>
+ runs.length === 1 && runs.every((run) => run.status === "succeeded"),
+ );
+ });
+}
+
+function breakTransform() {
+ cy.get<TransformId>("@transformId").then((transformId) => {
+ cy.request("PUT", `/api/ee/transform/${transformId}`, {
+ source: {
+ type: "query",
+ query: {
+ type: "native",
+ database: WRITABLE_DB_ID,
+ native: {
+ query: "SELECT 1 as score_new, 'active' as status_new",
+ },
+ },
+ },
+ });
+ H.runTransform(transformId);
+ H.waitForTransformRuns(
+ (runs) =>
+ runs.length === 2 && runs.every((run) => run.status === "succeeded"),
+ );
+ });
+}
+
+function createTableContent() {
+ H.getTableId({ name: TABLE_NAME }).then((tableId) => {
+ H.getFieldId({ tableId, name: "score" }).then((scoreFieldId) => {
+ H.getFieldId({ tableId, name: "status" }).then((statusFieldId) => {
+ H.createQuestion({
+ name: TABLE_BASED_QUESTION_BROKEN_FIELD,
+ database: WRITABLE_DB_ID,
+ query: {
+ "source-table": tableId,
+ fields: [["field", statusFieldId, null]],
+ },
+ });
+
+ H.createQuestion({
+ name: TABLE_BASED_QUESTION_BROKEN_EXPRESSION,
+ database: WRITABLE_DB_ID,
+ query: {
+ "source-table": tableId,
+ expressions: {
+ Expression: ["+", ["field", scoreFieldId, null], 0],
+ },
+ },
+ });
+
+ H.createQuestion({
+ name: TABLE_BASED_QUESTION_BROKEN_FILTER,
+ database: WRITABLE_DB_ID,
+ query: {
+ "source-table": tableId,
+ filter: ["=", ["field", scoreFieldId, null], 0],
+ },
+ });
+
+ H.createQuestion({
+ name: TABLE_BASED_QUESTION_BROKEN_BREAKOUT,
+ database: WRITABLE_DB_ID,
+ query: {
+ "source-table": tableId,
+ breakout: [["field", scoreFieldId, null]],
+ },
+ });
+
+ H.createQuestion({
+ name: TABLE_BASED_QUESTION_BROKEN_AGGREGATION,
+ database: WRITABLE_DB_ID,
+ query: {
+ "source-table": tableId,
+ aggregation: [["avg", ["field", scoreFieldId, null]]],
+ },
+ });
+
+ H.createQuestion({
+ name: TABLE_BASED_QUESTION_BROKEN_EXPLICIT_JOIN,
+ database: WRITABLE_DB_ID,
+ query: {
+ "source-table": tableId,
+ joins: [
+ {
+ "source-table": tableId,
+ alias: TABLE_DISPLAY_NAME,
+ condition: [
+ "=",
+ ["field", statusFieldId, null],
+ [
+ "field",
+ statusFieldId,
+ { "join-alias": TABLE_DISPLAY_NAME },
+ ],
+ ],
+ },
+ ],
+ aggregation: [
+ [
+ "max",
+ ["field", scoreFieldId, { "join-alias": TABLE_DISPLAY_NAME }],
+ ],
+ ],
+ },
+ });
+ });
+ });
+ });
+}
+
+function createQuestionContent() {
+ H.getTableId({ name: TABLE_NAME }).then((tableId) => {
+ H.createQuestion({
+ name: TABLE_BASED_QUESTION,
+ database: WRITABLE_DB_ID,
+ query: {
+ "source-table": tableId,
+ },
+ collection_id: ADMIN_PERSONAL_COLLECTION_ID,
+ }).then(({ body: card }) => {
+ H.createQuestion({
+ name: QUESTION_BASED_QUESTION_BROKEN_FILTER,
+ query: {
+ "source-table": `card__${card.id}`,
+ filter: [">", ["field", "PRICE", { "base-type": "type/Float" }], 10],
+ },
+ });
+ });
+ });
+}
+
+function createModelContent() {
+ H.getTableId({ name: TABLE_NAME }).then((tableId) => {
+ H.createQuestion({
+ name: TABLE_BASED_MODEL,
+ type: "model",
+ database: WRITABLE_DB_ID,
+ query: {
+ "source-table": tableId,
+ },
+ }).then(({ body: card }) => {
+ H.createQuestion({
+ name: MODEL_BASED_MODEL_BROKEN_AGGREGATION,
+ type: "model",
+ query: {
+ "source-table": `card__${card.id}`,
+ aggregation: [
+ ["distinct", ["field", "AMOUNT", { "base-type": "type/Integer" }]],
+ ],
+ },
+ });
+ });
+ });
+}
+
+function checkList({
+ visibleEntities = [],
+ hiddenEntities = [],
+}: {
+ visibleEntities?: string[];
+ hiddenEntities?: string[];
+}) {
+ H.DataStudio.Tasks.list().within(() => {
+ visibleEntities.forEach((name) => {
+ cy.findByText(name).should("exist");
+ });
+ hiddenEntities.forEach((name) => {
+ cy.findByText(name).should("not.exist");
+ });
+ });
+}
+
+function checkSidebar({
+ entityName,
+ transformName,
+ missingColumns,
+ brokenDependents,
+}: {
+ entityName: string;
+ transformName?: string;
+ missingColumns?: string[];
+ brokenDependents?: string[];
+}) {
+ H.DataStudio.Tasks.sidebar().within(() => {
+ H.DataStudio.Tasks.Sidebar.header()
+ .findByText(entityName)
+ .should("be.visible");
+ if (transformName) {
+ H.DataStudio.Tasks.Sidebar.transformInfo()
+ .findByText(transformName)
+ .should("exist");
+ }
+ if (missingColumns) {
+ H.DataStudio.Tasks.Sidebar.missingColumnsInfo().within(() => {
+ missingColumns.forEach((column) => {
+ cy.findByText(column).should("exist");
+ });
+ });
+ }
+ if (brokenDependents) {
+ H.DataStudio.Tasks.Sidebar.brokenDependentsInfo().within(() => {
+ brokenDependents.forEach((dependent) => {
+ cy.findByText(dependent).should("exist");
+ });
+ });
+ }
+ });
+}
+
+function checkListSorting({ visibleEntities }: { visibleEntities: string[] }) {
+ H.DataStudio.Tasks.list().within(() => {
+ visibleEntities.forEach((name, index) => {
+ cy.findByText(name)
+ .parents("[data-index]")
+ .should("have.attr", "data-index", index.toString());
+ });
+ });
+}
diff --git a/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts b/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts
index fa5e8f4f115..4476bb7fc6e 100644
--- a/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts
+++ b/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts
@@ -1,5 +1,3 @@
-const { H } = cy;
-
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import {
ADMIN_PERSONAL_COLLECTION_ID,
@@ -15,6 +13,7 @@ import type {
} from "metabase-types/api";
import { createMockParameter } from "metabase-types/api/mocks";
+const { H } = cy;
const { ORDERS_ID, PRODUCTS, PRODUCTS_ID } = SAMPLE_DATABASE;
const MODEL_FOR_QUESTION_DATA_SOURCE = "Model for question data source";
diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj b/enterprise/backend/src/metabase_enterprise/dependencies/api.clj
index 87055ee5685..66d7b89923b 100644
--- a/enterprise/backend/src/metabase_enterprise/dependencies/api.clj
+++ b/enterprise/backend/src/metabase_enterprise/dependencies/api.clj
@@ -1,8 +1,10 @@
(ns metabase-enterprise.dependencies.api
(:require
+ [clojure.set :as set]
[medley.core :as m]
[metabase-enterprise.dependencies.core :as dependencies]
[metabase-enterprise.dependencies.dependency-types :as deps.dependency-types]
+ [metabase-enterprise.dependencies.models.analysis-finding-error :as analysis-finding-error]
[metabase-enterprise.dependencies.models.dependency :as dependency]
[metabase-enterprise.transforms.schema :as transforms.schema]
[metabase.analyze.core :as analyze]
@@ -19,19 +21,19 @@
[metabase.lib.metadata :as lib.metadata]
[metabase.lib.schema.id :as lib.schema.id]
[metabase.lib.schema.metadata :as lib.schema.metadata]
- [metabase.lib.schema.validate :as lib.schema.validate]
[metabase.models.interface :as mi]
[metabase.native-query-snippets.core :as native-query-snippets]
[metabase.permissions.core :as perms]
[metabase.queries.schema :as queries.schema]
[metabase.request.core :as request]
[metabase.revisions.core :as revisions]
+ [metabase.util :as u]
[metabase.util.i18n :refer [tru]]
[metabase.util.malli :as mu]
[metabase.util.malli.registry :as mr]
[metabase.util.malli.schema :as ms]
[toucan2.core :as t2]
- [toucan2.util :as u]))
+ [toucan2.util :as t2.util]))
(mr/def ::card-body
[:merge
@@ -146,7 +148,7 @@
(broken-cards-response {})))
(def ^:private entity-keys
- {:table [:name :description :display_name :db_id :db :schema :fields]
+ {:table [:name :description :display_name :db_id :db :schema :fields :transform]
:card [:name :type :display :database_id :view_count :query_type
:created_at :creator :creator_id :description
:result_metadata :last-edit-info
@@ -178,11 +180,11 @@
(mr/def ::base-entity
[:map
- [:id pos-int?]
- [:type :keyword]
- [:data [:map]]
- [:dependents_count [:maybe [:ref ::usages]]]
- [:errors {:optional true} [:set [:ref ::lib.schema.validate/error]]]])
+ [:id pos-int?]
+ [:type :keyword]
+ [:data [:map]]
+ [:dependents_count [:maybe [:ref ::usages]]]
+ [:dependents_errors {:optional true} [:set [:ref ::analysis-finding-error/analysis-finding-error]]]])
(defn- fields-for [entity-key]
;; these specs should really use something like
@@ -274,7 +276,7 @@
:data (->> (select-keys entity (entity-keys entity-type))
(m/map-vals format-subentity))
:dependents_count (usages [entity-type id])}
- errors (assoc :errors (get errors [entity-type id]))))
+ errors (assoc :dependents_errors (get errors [entity-type id]))))
;; IMPORTANT: This map defines which fields to select when fetching entities for the dependency graph.
;; These field lists MUST be kept in sync with the frontend type definitions in:
@@ -410,6 +412,27 @@
:all nil)]}]])))))
deps.dependency-types/dependency-type->model)))
+(defn- broken-entities-filter-clause
+ "Returns a HoneySQL WHERE clause for filtering to only broken entities.
+
+ Accepts two arguments:
+ - `entity-type-field`: Database column name for entity type (e.g., :from_entity_type)
+ - `entity-id-field`: Database column name for entity ID (e.g., :from_entity_id)
+
+ Returns a clause that joins with the analysis_finding table to filter to entities
+ that have failed analysis (analysis_finding.result = false)."
+ [entity-type-field entity-id-field]
+ (into [:or]
+ (keep (fn [[entity-type _model]]
+ [:and
+ [:= entity-type-field (name entity-type)]
+ [:in entity-id-field {:select [:analyzed_entity_id]
+ :from [:analysis_finding]
+ :where [:and
+ [:= :analysis_finding.analyzed_entity_type (name entity-type)]
+ [:= :analysis_finding.result false]]}]])
+ deps.dependency-types/dependency-type->model)))
+
(defn- readable-graph-dependencies
([]
(readable-graph-dependencies nil))
@@ -421,10 +444,14 @@
(defn- readable-graph-dependents
([]
(readable-graph-dependents nil))
- ([opts]
+ ([{:keys [include-archived-items broken] :or {include-archived-items :exclude} :as _opts}]
(dependency/filtered-graph-dependents
(fn [entity-type-field entity-id-field]
- (visible-entities-filter-clause entity-type-field entity-id-field opts)))))
+ (let [visibility-clause (visible-entities-filter-clause entity-type-field entity-id-field
+ {:include-archived-items include-archived-items})]
+ (if broken
+ [:and visibility-clause (broken-entities-filter-clause entity-type-field entity-id-field)]
+ visibility-clause))))))
(defn- node-usages
"Calculates the count of direct dependents for all nodes in `nodes`, based on `graph`. "
@@ -447,39 +474,37 @@
(apply merge-with +)))
children-map)))
+(defn- node-downstream-errors
+ "Fetches errors caused by the given source entities (what downstream entities they're breaking).
+ Unlike `node-errors` which fetches errors on an entity, this fetches errors that
+ the entity is causing in other entities that depend on it."
+ [nodes-by-type]
+ (letfn [(errors-by-source-type-and-id [[source-type ids]]
+ (when (seq ids)
+ (let [finding-errors (t2/select :model/AnalysisFindingError
+ :source_entity_type source-type
+ :source_entity_id [:in ids])]
+ (u/group-by (juxt :source_entity_type :source_entity_id)
+ identity conj #{} finding-errors))))]
+ (->> nodes-by-type
+ (into {} (mapcat errors-by-source-type-and-id))
+ not-empty)))
+
(defn- node-errors
"Fetches and normalizes AnalysisFindingErrors for the given entities.
Returns {[entity-type entity-id] #{error-maps...}}, or nil if none."
[nodes-by-type]
(letfn [(normalize-finding-error
[{:keys [error_type error_detail]}]
- ;; error_type is stored without namespace (e.g. :missing-column)
- ;; but API schema expects :validate/missing-column
- (case error_type
- ;; These error types use :name
- (:validate/missing-column
- :validate/missing-table-alias
- :validate/duplicate-column)
- {:type error_type :name error_detail}
- ;; validation-exception-error uses :message
- :validate/validation-exception-error
- {:type error_type :message error_detail}
- ;; syntax-error has no additional fields
- :validate/syntax-error
- {:type error_type}
- ;; Default: use :name if detail exists
- (cond-> {:type error_type}
- error_detail (assoc :name error_detail))))
- (normalize-entity-errors [[[entity-type entity-id] errors]]
- (let [normalized-errors (into #{} (map normalize-finding-error) errors)]
- [[entity-type entity-id] normalized-errors]))
+ (cond-> {:type error_type}
+ error_detail (assoc :detail error_detail)))
(errors-by-entity-type-and-id [[type ids]]
- (let [finding-errors (t2/select :model/AnalysisFindingError
- :analyzed_entity_type type
- :analyzed_entity_id [:in ids])]
- (->> finding-errors
- (group-by (juxt :analyzed_entity_type :analyzed_entity_id))
- (map normalize-entity-errors))))]
+ (when (seq ids)
+ (let [finding-errors (t2/select :model/AnalysisFindingError
+ :analyzed_entity_type type
+ :analyzed_entity_id [:in ids])]
+ (u/group-by (juxt :analyzed_entity_type :analyzed_entity_id)
+ normalize-finding-error conj #{} finding-errors))))]
(->> nodes-by-type
(into {} (mapcat errors-by-entity-type-and-id))
not-empty)))
@@ -490,7 +515,7 @@
(t2/hydrate :creator :dashboard :document [:collection :is_personal])
(->> (map collection.root/hydrate-root-collection))
(revisions/with-last-edit-info :card))
- :table (t2/hydrate entities :fields :db)
+ :table (t2/hydrate entities :fields :db :transform)
:transform (-> entities
(t2/hydrate :creator :table-with-db-and-fields :last_run :collection)
(->> (map #(collection.root/hydrate-root-collection % (collection.root/hydrated-root-collection :transforms)))))
@@ -564,97 +589,140 @@
(def ^:private dependents-args
[:map
- [:id ms/PositiveInt]
- [:type ::deps.dependency-types/dependency-types]
- [:dependent_type ::deps.dependency-types/dependency-types]
- [:dependent_card_type {:optional true} (ms/enum-decode-keyword lib.schema.metadata/card-types)]
- [:archived {:optional true} :boolean]])
+ [:id ms/PositiveInt]
+ [:type ::deps.dependency-types/dependency-types]
+ [:dependent_types {:optional true}
+ [:or
+ ::deps.dependency-types/dependency-types
+ [:sequential ::deps.dependency-types/dependency-types]]]
+ [:dependent_card_types {:optional true}
+ [:or
+ (ms/enum-decode-keyword lib.schema.metadata/card-types)
+ [:sequential (ms/enum-decode-keyword lib.schema.metadata/card-types)]]]
+ [:archived {:optional true} :boolean]
+ [:broken {:optional true} :boolean]])
(api.macros/defendpoint :get "/graph/dependents" :- [:sequential ::entity]
- "This endpoint takes an :id, :type, :dependent_type, and an optional :dependent_card_type, and returns a list of
- all that entity's dependents with :dependent_type. If the :dependent_type is :card, the dependents are further
- filtered by :dependent_card_type.
-
- Optional :archived parameter controls whether entities in archived collections are included:
- - false (default): Excludes entities in archived collections
- - true: Includes entities in archived collections"
+ "Returns a list of dependents for the specified entity.
+
+ Required parameters:
+ - `id`: The ID of the entity
+ - `type`: The type of the entity (card, table, dashboard, etc.)
+
+ Optional parameters:
+ - `dependent_types`: Dependency types to filter by. Can be single value or array.
+ If not provided, returns all types. Example: ?dependent_types=card&dependent_types=dashboard
+ - `dependent_card_types`: Card types to filter by when dependent_types includes :card.
+ Ignored if dependent_types doesn't include :card. Example: ?dependent_card_types=question&dependent_card_types=model
+ - `archived`: Include entities in archived collections (default: false)
+ - `broken`: Return only broken entities (default: false)"
[_route-params
- {:keys [id type dependent_type dependent_card_type archived]} :- dependents-args]
+ {:keys [id type dependent_types dependent_card_types archived broken]} :- dependents-args]
(api/read-check (deps.dependency-types/dependency-type->model type) id)
(lib-be/with-metadata-provider-cache
- (let [graph-opts {:include-archived-items (if archived :all :exclude)}
+ (let [graph-opts {:include-archived-items (if archived :all :exclude)
+ :broken broken}
downstream-graph (graph/cached-graph (readable-graph-dependents graph-opts))
nodes (-> (graph/children-of downstream-graph [[type id]])
- (get [type id]))]
+ (get [type id]))
+ dep-types-set (cond
+ (nil? dependent_types) deps.dependency-types/dependency-types
+ (sequential? dependent_types) (set dependent_types)
+ :else #{dependent_types})
+ card-types-set (cond
+ (nil? dependent_card_types) lib.schema.metadata/card-types
+ (sequential? dependent_card_types) (set dependent_card_types)
+ :else #{dependent_card_types})]
(->> (expanded-nodes downstream-graph nodes {:include-errors? false})
- (filter #(and (= (:type %) dependent_type)
- (or (not= dependent_type :card)
- (= (-> % :data :type) dependent_card_type))))))))
-
-(defn- dependency-items-query
- [{:keys [query-type entity-type card-types query include-archived-items include-personal-collections sort-column]}]
- (let [table-name (case entity-type
- :card :report_card
- :table :metabase_table
- :transform :transform
- :snippet :native_query_snippet
- :dashboard :report_dashboard
- :document :document
- :sandbox :sandboxes
- :segment :segment
- :measure :measure)
- name-column (case entity-type
- :table :entity.display_name
- :sandbox [:cast :entity.id (if (= :mysql (mdb/db-type)) :char :text)]
- :entity.name)
- root-collection (collection.root/root-collection-with-ui-details (case entity-type
- :transform :transforms
- :snippet :snippets
- nil))
- location-column (case entity-type
- :card [:case
- [:not= :entity.dashboard_id nil] :dashboard.name
- [:not= :entity.document_id nil] :document.name
- :else [:coalesce :collection.name [:inline (:name root-collection)]]]
- :table :database.name
- (:transform :snippet :dashboard :document) [:coalesce :collection.name [:inline (:name root-collection)]]
- :sandbox [:cast :entity.id (if (= :mysql (mdb/db-type)) :char :text)]
- (:segment :measure) :table.display_name)
- dependents-count-column {:select [[:%count.*]]
- :from [:dependency]
- :where [:and
- [:= :dependency.to_entity_id :entity.id]
- [:= :dependency.to_entity_type [:inline (name entity-type)]]
- (visible-entities-filter-clause
- :dependency.from_entity_type
- :dependency.from_entity_id
- {:include-archived-items include-archived-items})]}
- dependency-join (case query-type
- :unreferenced [:dependency [:and
- [:= :dependency.to_entity_id :entity.id]
- [:= :dependency.to_entity_type [:inline (name entity-type)]]]]
- :broken [:analysis_finding [:and
- [:= :analysis_finding.analyzed_entity_id :entity.id]
- [:= :analysis_finding.analyzed_entity_type (name entity-type)]]])
- dependency-filter (case query-type
- :unreferenced [:= :dependency.id nil]
- :broken [:= :analysis_finding.result false])
- card-type-filter (when (and (= entity-type :card)
+ (filter (fn [node]
+ (and (or (nil? dep-types-set)
+ (contains? dep-types-set (:type node)))
+ (or (not= (:type node) :card)
+ (nil? card-types-set)
+ (contains? card-types-set (-> node :data :type))))))))))
+
+(defn- entity-type-config
+ [entity-type]
+ (let [root-collection (collection.root/root-collection-with-ui-details
+ (case entity-type
+ :transform :transforms
+ :snippet :snippets
+ nil))]
+ {:table-name (case entity-type
+ :card :report_card
+ :table :metabase_table
+ :transform :transform
+ :snippet :native_query_snippet
+ :dashboard :report_dashboard
+ :document :document
+ :sandbox :sandboxes
+ :segment :segment
+ :measure :measure)
+ :name-column (case entity-type
+ :table :entity.display_name
+ :sandbox [:cast :entity.id (if (= :mysql (mdb/db-type)) :char :text)]
+ :entity.name)
+ :location-column (case entity-type
+ :card [:case
+ [:not= :entity.dashboard_id nil] :dashboard.name
+ [:not= :entity.document_id nil] :document.name
+ :else [:coalesce :collection.name [:inline (:name root-collection)]]]
+ :table :database.name
+ (:transform :snippet :dashboard :document) [:coalesce :collection.name [:inline (:name root-collection)]]
+ :sandbox [:cast :entity.id (if (= :mysql (mdb/db-type)) :char :text)]
+ (:segment :measure) :table.display_name)}))
+
+(defn- query-type-join-and-filter
+ [query-type entity-type]
+ (case query-type
+ :unreferenced {:join [:dependency [:and
+ [:= :dependency.to_entity_id :entity.id]
+ [:= :dependency.to_entity_type (name entity-type)]]]
+ :filter [:= :dependency.id nil]}
+ :broken {:join [:analysis_finding [:and
+ [:= :analysis_finding.analyzed_entity_id :entity.id]
+ [:= :analysis_finding.analyzed_entity_type (name entity-type)]]]
+ :filter [:= :analysis_finding.result false]}
+ :breaking {:join [:analysis_finding_error [:and
+ [:= :analysis_finding_error.source_entity_id :entity.id]
+ [:= :analysis_finding_error.source_entity_type (name entity-type)]]]
+ :filter [:!= :analysis_finding_error.id nil]}))
+
+(defn- location-joins-for-entity
+ "Returns the set of join keywords needed for location-based operations."
+ [entity-type]
+ (case entity-type
+ :card #{:collection :dashboard :document}
+ (:transform :snippet :dashboard :document) #{:collection}
+ (:segment :measure) #{:table}
+ :table #{:database}
+ #{}))
+
+(defn- build-optional-filters
+ [{:keys [entity-type card-types query include-archived-items include-personal-collections]}
+ {:keys [name-column location-column]}]
+ (let [card-type-filter (when (and (= entity-type :card)
(seq card-types))
- [:in :entity.type (mapv name card-types)])
+ {:filter [:in :entity.type (mapv name card-types)]
+ :filter-joins #{}})
query-filter (when (and query (not= entity-type :sandbox))
- [:like [:lower name-column] (str "%" (u/lower-case-en query) "%")])
+ {:filter [:or
+ [:like [:lower name-column] (str "%" (t2.util/lower-case-en query) "%")]
+ [:like [:lower location-column] (str "%" (t2.util/lower-case-en query) "%")]]
+ :filter-joins (location-joins-for-entity entity-type)})
database-filter (when (= entity-type :table)
- [:and [:not :database.is_sample] [:not :database.is_audit]])
+ {:filter [:and [:not :database.is_sample] [:not :database.is_audit]]
+ :filter-joins #{:database}})
archived-filter (when (= include-archived-items :exclude)
- (case entity-type
- (:card :dashboard :document :snippet :segment :measure)
- [:= :entity.archived false]
- :table
- [:and
- [:= :entity.active true]
- [:= :entity.visibility_type nil]]
- nil))
+ {:filter (case entity-type
+ (:card :dashboard :document :snippet :segment :measure)
+ [:= :entity.archived false]
+ :table
+ [:and
+ [:= :entity.active true]
+ [:= :entity.visibility_type nil]]
+ nil)
+ :filter-joins #{}})
personal-filter (when-not include-personal-collections
(case entity-type
(:card :dashboard :document :snippet)
@@ -662,56 +730,71 @@
:personal_owner_id [:not= nil]
:location "/")]
(when (seq personal-ids)
- [:or
- [:= :entity.collection_id nil]
- [:and
- [:= :collection.personal_owner_id nil]
- (into [:and]
- (for [pid personal-ids]
- [:not-like :collection.location (str "/" pid "/%")]))]]))
+ {:filter [:or
+ [:= :entity.collection_id nil]
+ [:and
+ [:= :collection.personal_owner_id nil]
+ (into [:and]
+ (for [pid personal-ids]
+ [:not-like :collection.location (str "/" pid "/%")]))]]
+ :filter-joins #{:collection}}))
nil))
- sort-key-column (case sort-column
- :location location-column
- :dependents-count dependents-count-column
- name-column)
- sort-by-location? (= sort-column :location)
- needs-database-join? (= entity-type :table)
- needs-collection-join? (or (and (not include-personal-collections)
- (#{:card :dashboard :document :snippet} entity-type))
- (and sort-by-location?
- (#{:card :transform :snippet :dashboard :document} entity-type)))
- needs-dashboard-join? (and sort-by-location? (= entity-type :card))
- needs-document-join? (and sort-by-location? (= entity-type :card))
- needs-table-join? (and sort-by-location? (#{:segment :measure} entity-type))]
- {:select [[[:inline (name entity-type)] :entity_type]
- [:entity.id :entity_id]
- [sort-key-column :sort_key]]
- :from [[table-name :entity]]
- :left-join (cond-> dependency-join
- needs-database-join? (conj [:metabase_database :database] [:= :entity.db_id :database.id])
- needs-collection-join? (conj :collection [:= :entity.collection_id :collection.id])
- needs-dashboard-join? (conj [:report_dashboard :dashboard] [:= :entity.dashboard_id :dashboard.id])
- needs-document-join? (conj :document [:= :entity.document_id :document.id])
- needs-table-join? (conj [:metabase_table :table] [:= :entity.table_id :table.id]))
- :where (cond->> dependency-filter
- card-type-filter
- (conj [:and card-type-filter])
-
- query-filter
- (conj [:and query-filter])
-
- database-filter
- (conj [:and database-filter])
+ filter-results (keep identity
+ [card-type-filter query-filter database-filter archived-filter personal-filter])]
+ {:filters (keep :filter filter-results)
+ :filter-joins (reduce set/union #{} (map :filter-joins filter-results))}))
+
+(defn- sort-key-cols-and-joins
+ [sort-column entity-type name-column location-column]
+ (case sort-column
+ :location {:sort-column location-column
+ :sort-joins (location-joins-for-entity entity-type)}
+ :dependents-errors {:sort-column {:select [[[:count [:distinct (if (= :mysql (mdb/db-type))
+ [:concat :error_type [:inline "-"] [:coalesce :error_detail [:inline ""]]]
+ [:composite :error_type :error_detail])]]]]
+ :from [:analysis_finding_error]
+ :where [:and
+ [:= :source_entity_id :entity.id]
+ [:= :source_entity_type (name entity-type)]]}
+ :sort-joins #{}}
+ :dependents-with-errors {:sort-column {:select [[[:count [:distinct (if (= :mysql (mdb/db-type))
+ [:concat :analyzed_entity_id [:inline "-"] :analyzed_entity_type]
+ [:composite :analyzed_entity_id :analyzed_entity_type])]]]]
+ :from [:analysis_finding_error]
+ :where [:and
+ [:= :source_entity_id :entity.id]
+ [:= :source_entity_type (name entity-type)]]}
+ :sort-joins #{}}
+ {:sort-column name-column
+ :sort-joins #{}}))
+
+(defn- build-left-joins
+ [base-join joins]
+ (cond-> base-join
+ (:database joins) (conj [:metabase_database :database] [:= :entity.db_id :database.id])
+ (:collection joins) (conj :collection [:= :entity.collection_id :collection.id])
+ (:dashboard joins) (conj [:report_dashboard :dashboard] [:= :entity.dashboard_id :dashboard.id])
+ (:document joins) (conj :document [:= :entity.document_id :document.id])
+ (:table joins) (conj [:metabase_table :table] [:= :entity.table_id :table.id])))
- archived-filter
- (conj [:and archived-filter])
-
- personal-filter
- (conj [:and personal-filter]))}))
+(defn- dependency-items-query
+ [{:keys [query-type entity-type sort-column] :as params}]
+ (let [{:keys [table-name name-column location-column] :as config} (entity-type-config entity-type)
+ {:keys [join filter]} (query-type-join-and-filter query-type entity-type)
+ {:keys [filters filter-joins]} (build-optional-filters params config)
+ {:keys [sort-column sort-joins]} (sort-key-cols-and-joins sort-column entity-type name-column location-column)
+ all-required-joins (set/union filter-joins sort-joins)
+ select-clause [[[:inline (name entity-type)] :entity_type]
+ [:entity.id :entity_id]
+ [sort-column :sort_key]]]
+ {(if (= query-type :breaking) :select-distinct :select) select-clause
+ :from [[table-name :entity]]
+ :left-join (build-left-joins join all-required-joins)
+ :where (into [:and filter] (keep identity) filters)}))
(def ^:private sort-columns
"Valid sort columns for dependency item endpoints."
- #{:name :location :dependents-count})
+ #{:name :location :dependents-with-errors :dependents-errors})
(def ^:private sort-directions
"Valid sort directions for dependency item endpoints."
@@ -748,7 +831,7 @@
- `query`: Search string to filter by name or location
- `archived`: Controls whether archived entities are included
- `include_personal_collections`: Controls whether items in personal collections are included (default: false)
- - `sort_column`: Sort column - `:name`, `:location`, or `:dependents-count` (default: `:name`)
+ - `sort_column`: Sort column - `:name`, `:location`, `:dependents-errors`, or `:dependents-with-errors` (default: `:name`)
- `sort_direction`: Sort direction - `:asc` or `:desc` (default: `:asc`)
- `offset`: Default 0
- `limit`: Default 50
@@ -799,27 +882,29 @@
:total total}))
(api.macros/defendpoint :get "/graph/broken" :- dependency-items-response
- "Returns a list of all items with broken queries.
+ "Returns a list of entities that are causing errors in downstream dependents
+ These are tables or cards that other entities depend on, where those dependents
+ have validation errors traced back to this source entity.
Accepts optional parameters for filtering:
- - `types`: List of entity types to include (e.g., `[:card :transform :snippet :dashboard]`)
+ - `types`: List of source entity types - only `:card` or `:table` (default: both)
- `card_types`: List of card types to include when filtering cards (e.g., `[:question :model :metric]`)
- `query`: Search string to filter by name or location
- `archived`: Controls whether archived entities are included
- `include_personal_collections`: Controls whether items in personal collections are included (default: false)
- - `sort_column`: Sort column - `:name`, `:location`, or `:dependents-count` (default: `:name`)
+ - `sort_column`: Sort column - `:name`, `:location`, `:dependents-errors`, or `:dependents-with-errors` (default: `:name`)
- `sort_direction`: Sort direction - `:asc` or `:desc` (default: `:asc`)
- `offset`: Default 0
- `limit`: Default 50
Returns a map with:
- - `data`: List of broken items, each with `:id`, `:type`, `:data`, and `:error`s fields
+ - `data`: List of breaking source entities
- `total`: Total count of matched items
- `offset`: Applied offset
- `limit`: Applied limit"
[_route-params
{:keys [types card_types query archived include_personal_collections sort_column sort_direction]
- :or {types (vec deps.dependency-types/dependency-types)
+ :or {types [:card :table]
card_types (vec lib.schema.metadata/card-types)
include_personal_collections false
sort_column :name
@@ -832,7 +917,7 @@
;; Sandboxes don't support query filtering, so exclude them when a query is provided
query (remove #{:sandbox}))
card-types (if (sequential? card_types) card_types [card_types])
- union-queries (map #(dependency-items-query {:query-type :broken
+ union-queries (map #(dependency-items-query {:query-type :breaking
:entity-type %
:card-types card-types
:query query
@@ -848,11 +933,24 @@
(map (fn [{:keys [entity_id entity_type]}]
[(keyword entity_type) entity_id])))
downstream-graph (graph/cached-graph (readable-graph-dependents graph-opts))
+ nodes-by-type (u/group-by first second all-ids)
+ downstream-errors (node-downstream-errors nodes-by-type)
total (-> (t2/query {:select [[:%count.* :total]]
:from [[union-query :subquery]]})
first
- :total)]
- {:data (expanded-nodes downstream-graph all-ids {:include-errors? true})
+ :total)
+ usages (node-usages downstream-graph all-ids)
+ fetch-entity (fn [entity-type entity-id]
+ (let [model (deps.dependency-types/dependency-type->model entity-type)
+ fields (entity-select-fields entity-type)]
+ (t2/select-one (into [model] fields) :id entity-id)))
+ data (into []
+ (keep (fn [[entity-type entity-id]]
+ (when-let [entity (fetch-entity entity-type entity-id)]
+ (let [hydrated (first (hydrate-entities entity-type [entity]))]
+ (entity-value entity-type hydrated usages downstream-errors)))))
+ all-ids)]
+ {:data data
:offset offset
:limit limit
:total total}))
diff --git a/enterprise/backend/src/metabase_enterprise/dependencies/models/analysis_finding_error.clj b/enterprise/backend/src/metabase_enterprise/dependencies/models/analysis_finding_error.clj
index e3cff70b6bf..8ba45839374 100644
--- a/enterprise/backend/src/metabase_enterprise/dependencies/models/analysis_finding_error.clj
+++ b/enterprise/backend/src/metabase_enterprise/dependencies/models/analysis_finding_error.clj
@@ -6,7 +6,6 @@
[metabase-enterprise.dependencies.dependency-types :as deps.dependency-types]
[metabase.lib.schema.validate :as lib.schema.validate]
[metabase.models.interface :as mi]
- [metabase.util :as u]
[metabase.util.malli :as mu]
[metabase.util.malli.registry :as mr]
[metabase.util.malli.schema :as ms]
@@ -44,7 +43,7 @@
(mu/defn replace-errors-for-entity!
"Delete existing errors for an entity and insert new ones.
`errors` is a sequence of maps with keys:
- - `:error-type` - keyword like `:validate/missing-column`
+ - `:error-type` - keyword like `:missing-column`
- `:error-detail` - string (column name, alias, message, etc.) or nil
- `:source-entity-type` - keyword like `:table`, `:card`, or nil
- `:source-entity-id` - int or nil"
@@ -60,7 +59,7 @@
(mapv (fn [{:keys [error-type error-detail source-entity-type source-entity-id]}]
{:analyzed_entity_type (name entity-type)
:analyzed_entity_id entity-id
- :error_type (u/qualified-name error-type)
+ :error_type error-type
:error_detail error-detail
:source_entity_type (some-> source-entity-type name)
:source_entity_id source-entity-id})
diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj
index c1fccf973b3..46e75c1477d 100644
--- a/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/dependencies/api_test.clj
@@ -8,18 +8,20 @@
[metabase.collections.models.collection :as collection]
[metabase.core.core :as mbc]
[metabase.events.core :as events]
+ [metabase.lib-be.core :as lib-be]
[metabase.lib.core :as lib]
[metabase.lib.metadata :as lib.metadata]
[metabase.native-query-snippets.models.native-query-snippet.permissions :as snippet.perms]
[metabase.permissions.core :as perms]
[metabase.queries.models.card :as card]
[metabase.test :as mt]
- [metabase.util :as u]))
+ [metabase.util :as u]
+ [toucan2.core :as t2]))
(comment
metabase-enterprise.dependencies.events/keep-me)
-(defn card-with-query
+(defn- card-with-query
"Create a card map with the given name and dataset query."
[card-name dataset-query]
{:name card-name
@@ -30,7 +32,7 @@
:dataset_query dataset-query
:visualization_settings {}})
-(defn basic-card
+(defn- basic-card
"Construct a basic card for dependency testing."
([]
(basic-card "Test card"))
@@ -40,19 +42,19 @@
(let [mp (mt/metadata-provider)]
(card-with-query card-name (lib/query mp (lib.metadata/table mp (mt/id table-keyword)))))))
-(defn wrap-card-query
+(defn- wrap-card-query
"Construct a query depending on `inner-card` for dependency testing."
[inner-card]
(let [mp (mt/metadata-provider)
card-meta (lib.metadata/card mp (:id inner-card))]
(lib/query mp card-meta)))
-(defn wrap-card
+(defn- wrap-card
"Construct a card depending on `inner-card` for dependency testing."
[inner-card]
(card-with-query "Downstream card" (wrap-card-query inner-card)))
-(defn wrap-two-cards
+(defn- wrap-two-cards
"Construct a card depending on both `card1` and `card2` via a join."
[card1 card2]
(let [mp (mt/metadata-provider)
@@ -77,6 +79,54 @@
(-> (lib/query mp (lib.metadata/table mp (mt/id :products)))
(lib/aggregate (lib/sum (lib.metadata/field mp (mt/id :orders :total)))))))
+(defn- create-model-card!
+ "Create a model card with the given name and optional collection-id.
+ Returns the created card."
+ [user card-name & {:keys [collection-id archived]}]
+ (let [mp (mt/metadata-provider)
+ orders (lib.metadata/table mp (mt/id :orders))]
+ (card/create-card! (m/assoc-some {:name card-name
+ :database_id (mt/id)
+ :display :table
+ :query_type :query
+ :type :model
+ :dataset_query (lib/query mp orders)
+ :visualization_settings {}}
+ :collection_id collection-id
+ :archived archived)
+ user)))
+
+(defn- create-dependent-card-on-model!
+ [user model-card card-name & {:keys [collection-id table] :or {table :orders}}]
+ (let [mp (mt/metadata-provider)
+ model-meta (lib.metadata/card mp (:id model-card))
+ q (lib/query mp model-meta)
+ cols (lib/filterable-columns q)
+ filter-col-name (case table
+ :products :price
+ :total)
+
+ filter-col (m/find-first #(= (:id %) (mt/id table filter-col-name)) cols)
+ dependent-query (lib/filter q (lib/> filter-col 100))]
+ (card/create-card! (cond-> (card-with-query card-name dependent-query)
+ collection-id (assoc :collection_id collection-id))
+ user)))
+
+(defn- break-model-card!
+ "Update a model card to query the products table instead of orders.
+ This breaks any downstream cards that depend on columns only in the orders table (like TOTAL)."
+ [model-card]
+ (let [mp (mt/metadata-provider)
+ products (lib.metadata/table mp (mt/id :products))]
+ (card/update-card! {:card-before-update model-card
+ :card-updates {:dataset_query (lib/query mp products)}})))
+
+(defn- run-analysis-for-card!
+ "Run analysis for a specific card to detect broken references.
+ Must be called within lib-be/with-metadata-provider-cache."
+ [card-id]
+ (dependencies.findings/upsert-analysis! (t2/select-one :model/Card :id card-id)))
+
(deftest check-card-test
(testing "POST /api/ee/dependencies/check_card"
(mt/with-premium-features #{:dependencies}
@@ -399,8 +449,8 @@
response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph/dependents"
:id card-id-1
:type "card"
- :dependent_type "card"
- :dependent_card_type "question")]
+ :dependent_types "card"
+ :dependent_card_types "question")]
(is (=? [{:data
{:collection
{:id "root"
@@ -420,6 +470,84 @@
:type "card"}]
response))))))))
+(deftest ^:sequential dependents-multiple-types-test
+ (testing "GET /api/ee/dependencies/graph/dependents with multiple dependent_types"
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-model-cleanup [:model/Card :model/Dependency :model/DashboardCard]
+ (mt/with-temp [:model/User user {:email "[email protected]"}
+ :model/Dashboard {dashboard-id :id} {:name "Test Dashboard"}]
+ (let [{card-id-1 :id :as dependency-card} (card/create-card! (basic-card "Base card - multi") user)
+ _dependent-card (card/create-card! (wrap-card dependency-card) user)]
+ (t2/insert! :model/DashboardCard {:dashboard_id dashboard-id
+ :card_id card-id-1
+ :row 0
+ :col 0
+ :size_x 4
+ :size_y 4})
+ (while (#'dependencies.backfill/backfill-dependencies!))
+ (testing "single dependent_types value (backward compatibility)"
+ (let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph/dependents"
+ :id card-id-1
+ :type "card"
+ :dependent_types "card")]
+ (is (= 1 (count response)))
+ (is (every? #(= "card" (:type %)) response))))
+ (testing "multiple dependent_types via repeated params"
+ (let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph/dependents"
+ :id card-id-1
+ :type "card"
+ :dependent_types "card"
+ :dependent_types "dashboard")]
+ (is (= 2 (count response)))
+ (is (= #{"card" "dashboard"} (set (map :type response))))))
+ (testing "no dependent_types returns all types"
+ (let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph/dependents"
+ :id card-id-1
+ :type "card")]
+ (is (>= (count response) 2))
+ (is (contains? (set (map :type response)) "card"))
+ (is (contains? (set (map :type response)) "dashboard"))))))))))
+
+(deftest ^:sequential dependents-multiple-card-types-test
+ (testing "GET /api/ee/dependencies/graph/dependents with multiple dependent_card_types"
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-model-cleanup [:model/Card :model/Dependency]
+ (mt/with-temp [:model/User user {:email "[email protected]"}]
+ (let [{dependency-card-id :id :as dependency-card} (card/create-card! (basic-card "Base card - cardtypes") user)
+ _question-card (card/create-card! (assoc (wrap-card dependency-card) :name "Question card") user)
+ _model-card (card/create-card! (assoc (wrap-card dependency-card) :name "Model card" :type :model) user)]
+ (testing "single dependent_card_types value"
+ (let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph/dependents"
+ :id dependency-card-id
+ :type "card"
+ :dependent_types "card"
+ :dependent_card_types "question")]
+ (is (= 1 (count response)))
+ (is (= "question" (-> response first :data :type)))))
+ (testing "multiple dependent_card_types via repeated params"
+ (let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph/dependents"
+ :id dependency-card-id
+ :type "card"
+ :dependent_types "card"
+ :dependent_card_types "question"
+ :dependent_card_types "model")]
+ (is (= 2 (count response)))
+ (is (= #{"question" "model"} (set (map #(-> % :data :type) response))))))
+ (testing "no dependent_card_types returns all card types"
+ (let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph/dependents"
+ :id dependency-card-id
+ :type "card"
+ :dependent_types "card")]
+ (is (= 2 (count response)))
+ (is (= #{"question" "model"} (set (map #(-> % :data :type) response))))))
+ (testing "dependent_card_types ignored when dependent_types doesn't include card"
+ (let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph/dependents"
+ :id dependency-card-id
+ :type "card"
+ :dependent_types "dashboard"
+ :dependent_card_types "question")]
+ (is (every? #(= "dashboard" (:type %)) response))))))))))
+
(deftest graph-archived-card-test
(testing "GET /api/ee/dependencies/graph with archived parameter"
(mt/with-premium-features #{:dependencies}
@@ -459,18 +587,42 @@
(let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph/dependents"
:id (:id base-card)
:type "card"
- :dependent_type "card")]
+ :dependent_types "card")]
(is (empty? response))))
(testing "archived=true includes archived dependent"
(let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph/dependents"
:id (:id base-card)
:type "card"
- :dependent_type "card"
- :dependent_card_type "question"
+ :dependent_types "card"
+ :dependent_card_types "question"
:archived true)
dependent-ids (set (map :id response))]
(is (contains? dependent-ids (:id dependent-card)))))))))))
+(deftest ^:sequential dependents-broken-parameter-test
+ (testing "GET /api/ee/dependencies/graph/dependents?broken=true - only returns entities that are broken"
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-temp [:model/User user {:email "[email protected]"}]
+ (mt/with-model-cleanup [:model/Card :model/Dependency :model/AnalysisFinding :model/AnalysisFindingError]
+ ;; Create cards in one metadata provider cache session
+ (let [[model-card dependent-card] (lib-be/with-metadata-provider-cache
+ (let [model-card (create-model-card! user "Model Card - brokentest")
+ dependent-card (create-dependent-card-on-model! user model-card "Dependent Card - brokentest")]
+ [model-card dependent-card]))]
+ ;; Run analysis in a fresh metadata provider cache session to detect the broken reference
+ (lib-be/with-metadata-provider-cache
+ (break-model-card! model-card)
+ (let [next-card (create-dependent-card-on-model! user model-card "Another Dependent Card - brokentest" {:table :products})]
+ (while (#'dependencies.backfill/backfill-dependencies!))
+ (run-analysis-for-card! (:id next-card))
+ (run-analysis-for-card! (:id dependent-card))
+ (let [response2 (mt/user-http-request :crowberto :get 200 (str "ee/dependencies/graph/dependents?broken=true&type=card&id=" (:id model-card)))]
+ (is (= [(:id dependent-card)] (mapv :id response2))
+ "There should be one broken dependent"))
+ (let [response2 (mt/user-http-request :crowberto :get 200 (str "ee/dependencies/graph/dependents?broken=false&type=card&id=" (:id model-card)))]
+ (is (= #{(:id dependent-card) (:id next-card)} (set (map :id response2)))
+ "There should two dependents total"))))))))))
+
(deftest check-card-permissions-test
(testing "POST /api/ee/dependencies/check_card requires read permissions on the input card"
(mt/with-premium-features #{:dependencies}
@@ -558,15 +710,15 @@
(mt/user-http-request :rasta :get 403 "ee/dependencies/graph/dependents"
:id card-id
:type "card"
- :dependent_type "card"
- :dependent_card_type "question"))))
+ :dependent_types "card"
+ :dependent_card_types "question"))))
(testing "Returns 200 when user has read permissions"
(perms/grant-collection-read-permissions! (perms/all-users-group) collection)
(mt/user-http-request :rasta :get 200 "ee/dependencies/graph/dependents"
:id card-id
:type "card"
- :dependent_type "card"
- :dependent_card_type "question")))))))))
+ :dependent_types "card"
+ :dependent_card_types "question")))))))))
(deftest graph-filtering-test
(testing "GET /api/ee/dependencies/graph filters out upstream nodes the user cannot read"
@@ -629,8 +781,8 @@
(let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph/dependents"
:id (:id base-card)
:type "card"
- :dependent_type "card"
- :dependent_card_type "question")
+ :dependent_types "card"
+ :dependent_card_types "question")
dependent-ids (set (map :id response))]
(is (contains? dependent-ids (:id readable-dependent)))
(is (not (contains? dependent-ids (:id unreadable-dependent)))))))))))))
@@ -750,8 +902,8 @@
(let [response (mt/user-http-request :rasta :get 200 "ee/dependencies/graph/dependents"
:id snippet-id
:type "snippet"
- :dependent_type "card"
- :dependent_card_type "question")
+ :dependent_types "card"
+ :dependent_card_types "question")
dependent-ids (set (map :id response))]
(is (contains? dependent-ids (:id readable-card))
"Should see readable card as dependent")
@@ -811,8 +963,8 @@
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/dependents"
:id (:id base-card)
:type :card
- :dependent_type :card
- :dependent_card_type :question)
+ :dependent_types :card
+ :dependent_card_types :question)
card-node (first (filter #(= (:id %) (:id dashboard-card)) response))]
(is (some? card-node))
(is (= {:id (:id dashboard) :name "Test Dashboard"}
@@ -843,8 +995,8 @@
(let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/dependents"
:id (:id base-card)
:type :card
- :dependent_type :card
- :dependent_card_type :question)
+ :dependent_types :card
+ :dependent_card_types :question)
card-node (first (filter #(= (:id %) (:id document-card)) response))]
(is (some? card-node))
(is (= {:id (:id document) :name "Test Document"}
@@ -893,8 +1045,8 @@
response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/dependents"
:id segment-id
:type "segment"
- :dependent_type "card"
- :dependent_card_type "question")]
+ :dependent_types "card"
+ :dependent_card_types "question")]
(testing "returns card that uses the segment"
(is (= 1 (count response)))
(is (= (:id card) (:id (first response))))))))))))
@@ -982,8 +1134,8 @@
response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/dependents"
:id measure-id
:type "measure"
- :dependent_type "card"
- :dependent_card_type "question")]
+ :dependent_types "card"
+ :dependent_card_types "question")]
(testing "returns card that uses the measure"
(is (= 1 (count response)))
(is (= (:id card) (:id (first response))))))))))))
@@ -1451,127 +1603,6 @@
:total 0}
(mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/unreferenced?types=table&query=notification")))))))
-(deftest ^:sequential broken-questions-test
- (testing "GET /api/ee/dependencies/broken - only broken questions are returned"
- (mt/with-premium-features #{:dependencies}
- (let [mp (mt/metadata-provider)
- products (lib.metadata/table mp (mt/id :products))]
- (mt/with-temp [:model/Card _ {:name "Good Card - brokentest"
- :type :question
- :dataset_query (lib/query mp products)}
- :model/Card {broken-card-id :id} {:name "Broken Card - brokentest"
- :type :question
- :dataset_query (broken-mbql-query)}]
- (while (> (dependencies.findings/analyze-batch! :card 50) 0))
- (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=question&query=brokentest")]
- (is (=? {:data [{:id broken-card-id
- :type "card"
- :data {:name "Broken Card - brokentest"}}]}
- response))))))))
-
-(deftest ^:sequential broken-transforms-test
- (testing "GET /api/ee/dependencies/broken - only broken transforms are returned"
- (mt/with-premium-features #{:dependencies}
- (let [mp (mt/metadata-provider)
- products (lib.metadata/table mp (mt/id :products))]
- (mt/with-temp [:model/Transform {broken-transform-id :id} {:name "Broken Transform - brokentest"
- :source {:type :query
- :query (broken-mbql-query)}
- :target {:schema "PUBLIC"
- :name "broken_transform_table"}}
- :model/Transform _ {:name "Good Transform - brokentest"
- :source {:type :query
- :query (lib/query mp products)}
- :target {:schema "PUBLIC"
- :name "referenced_transform_table"}}]
- (while (> (dependencies.findings/analyze-batch! :transform 50) 0))
- (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=transform&query=brokentest")]
- (is (=? {:data [{:id broken-transform-id
- :type "transform"
- :data {:name "Broken Transform - brokentest"}}]}
- response))))))))
-
-(deftest ^:sequential broken-card-types-test
- (testing "GET /api/ee/dependencies/broken - broken models and metrics are filtered by card_types and pagination"
- (mt/with-premium-features #{:dependencies}
- (mt/with-temp [:model/Card {broken-model-id :id} {:name "A - Broken Model - cardtype"
- :type :model
- :dataset_query (broken-mbql-query)}
- :model/Card {broken-metric-id :id} {:name "B - Broken Metric - cardtype"
- :type :metric
- :dataset_query (broken-mbql-query)}]
- (while (> (dependencies.findings/analyze-batch! :card 50) 0))
- (testing "filtering by model only"
- (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=model&query=cardtype")]
- (is (=? {:data [{:id broken-model-id
- :type "card"
- :data {:name "A - Broken Model - cardtype"
- :type "model"}}]}
- response))))
- (testing "filtering by metric only"
- (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=metric&query=cardtype")]
- (is (=? {:data [{:id broken-metric-id
- :type "card"
- :data {:name "B - Broken Metric - cardtype"
- :type "metric"}}]}
- response))))
- (testing "filtering by model and metric as the default card types"
- (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&query=cardtype")]
- (is (=? {:data [{:id broken-model-id
- :type "card"
- :data {:name "A - Broken Model - cardtype"
- :type "model"}}
- {:id broken-metric-id
- :type "card"
- :data {:name "B - Broken Metric - cardtype"
- :type "metric"}}]}
- response))))))))
-
-(deftest ^:sequential broken-archived-card-test
- (testing "GET /api/ee/dependencies/graph/broken with archived parameter"
- (mt/with-premium-features #{:dependencies}
- (mt/with-temp [:model/Card {broken-card-id :id} {:name "Broken Card - archivedbrokentestcard"
- :type :question
- :dataset_query (broken-mbql-query)}
- :model/Card {archived-broken-card-id :id} {:name "Archived Broken Card - archivedbrokentestcard"
- :type :question
- :archived true
- :dataset_query (broken-mbql-query)}]
- (while (> (dependencies.findings/analyze-batch! :card 50) 0))
- (testing "archived=false (default) excludes archived broken card"
- (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=question&query=archivedbrokentestcard")
- card-ids (set (map :id (:data response)))]
- (is (contains? card-ids broken-card-id))
- (is (not (contains? card-ids archived-broken-card-id)))))
- (testing "archived=true includes archived broken card"
- (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=question&query=archivedbrokentestcard&archived=true")
- card-ids (set (map :id (:data response)))]
- (is (contains? card-ids broken-card-id))
- (is (contains? card-ids archived-broken-card-id))))))))
-
-(deftest ^:sequential broken-archived-segment-test
- (testing "GET /api/ee/dependencies/graph/broken with archived parameter for segments"
- (mt/with-premium-features #{:dependencies}
- ;; Use a filter referencing a non-existent field ID (999999) to create a "broken" segment
- (mt/with-temp [:model/Segment {broken-segment-id :id} {:name "Broken Segment - archivedbrokentest"
- :table_id (mt/id :products)
- :definition {:filter [:> [:field 999999 nil] 50]}}
- :model/Segment {archived-broken-segment-id :id} {:name "Archived Broken Segment - archivedbrokentest"
- :table_id (mt/id :products)
- :definition {:filter [:> [:field 999999 nil] 50]}
- :archived true}]
- (while (> (dependencies.findings/analyze-batch! :segment 50) 0))
- (testing "archived=false (default) excludes archived broken segment"
- (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=segment&query=archivedbrokentest")
- segment-ids (set (map :id (:data response)))]
- (is (contains? segment-ids broken-segment-id))
- (is (not (contains? segment-ids archived-broken-segment-id)))))
- (testing "archived=true includes archived broken segment"
- (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=segment&query=archivedbrokentest&archived=true")
- segment-ids (set (map :id (:data response)))]
- (is (contains? segment-ids broken-segment-id))
- (is (contains? segment-ids archived-broken-segment-id))))))))
-
(deftest ^:sequential unreferenced-archived-measure-test
(testing "GET /api/ee/dependencies/graph/unreferenced with archived parameter for measures"
(mt/with-premium-features #{:dependencies}
@@ -1660,53 +1691,6 @@
(is (contains? dashboard-ids dash-in-personal))
(is (contains? dashboard-ids dash-regular)))))))))
-(deftest ^:sequential broken-personal-collection-card-test
- (testing "GET /api/ee/dependencies/graph/broken with include_personal_collections parameter"
- (mt/with-premium-features #{:dependencies}
- (binding [collection/*allow-deleting-personal-collections* true]
- (mt/with-temp [:model/User {user-id :id} {}
- :model/Collection {personal-coll-id :id} {:personal_owner_id user-id
- :name "Test Personal Collection"}
- :model/Card {broken-in-personal :id} {:name "Broken Card in Personal - personalcollbrokentest"
- :type :question
- :collection_id personal-coll-id
- :dataset_query (broken-mbql-query)}
- :model/Card {broken-regular :id} {:name "Broken Card Regular - personalcollbrokentest"
- :type :question
- :dataset_query (broken-mbql-query)}]
- (while (> (dependencies.findings/analyze-batch! :card 50) 0))
- (testing "include_personal_collections=false (default) excludes broken cards in personal collections"
- (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=question&query=personalcollbrokentest")
- card-ids (set (map :id (:data response)))]
- (is (not (contains? card-ids broken-in-personal)))
- (is (contains? card-ids broken-regular))))
- (testing "include_personal_collections=true includes broken cards in personal collections"
- (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=question&query=personalcollbrokentest&include_personal_collections=true")
- card-ids (set (map :id (:data response)))]
- (is (contains? card-ids broken-in-personal))
- (is (contains? card-ids broken-regular)))))))))
-
-(deftest ^:sequential broken-pagination-test
- (testing "GET /api/ee/dependencies/broken - should paginate results"
- (mt/with-premium-features #{:dependencies}
- (mt/with-temp [:model/Card {card1-id :id} {:name "Card 1 - brokentest"
- :type :question
- :dataset_query (broken-mbql-query)}
- :model/Card {card2-id :id} {:name "Card 2 - brokentest"
- :type :question
- :dataset_query (broken-mbql-query)}]
- (while (> (dependencies.findings/analyze-batch! :card 50) 0))
- (is (=? {:data [{:id card1-id}]
- :total 2
- :offset 0
- :limit 1}
- (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=question&query=brokentest&offset=0&limit=1")))
- (is (=? {:data [{:id card2-id}]
- :total 2
- :offset 1
- :limit 1}
- (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&card_types=question&query=brokentest&offset=1&limit=1")))))))
-
(deftest ^:sequential unreferenced-sort-by-name-test
(testing "GET /api/ee/dependencies/graph/unreferenced - sorting by name"
(mt/with-premium-features #{:dependencies}
@@ -1829,76 +1813,337 @@
(= sort-direction :desc) reverse)
names))))))))
-(deftest ^:sequential broken-sort-by-name-test
+(deftest ^:sequential broken-entities-returns-source-of-errors-test
+ (testing "GET /api/ee/dependencies/graph/broken - returns entities that are SOURCE of downstream errors"
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-temp [:model/User user {:email "[email protected]"}]
+ (mt/with-model-cleanup [:model/Card :model/Dependency :model/AnalysisFinding :model/AnalysisFindingError]
+ ;; Create cards in one metadata provider cache session
+ (let [[model-card dependent-card]
+ (lib-be/with-metadata-provider-cache
+ (let [model-card (create-model-card! user "Model Card - brokentest")
+ dependent-card (create-dependent-card-on-model! user model-card "Dependent Card - brokentest")]
+ [model-card dependent-card]))]
+ (lib-be/with-metadata-provider-cache
+ (break-model-card! model-card))
+ ;; Run analysis in a fresh metadata provider cache session to detect the broken reference
+ (lib-be/with-metadata-provider-cache
+ (while (#'dependencies.backfill/backfill-dependencies!))
+ (run-analysis-for-card! (:id dependent-card)))
+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&query=brokentest")]
+ (is (= [(:id model-card)] (mapv :id (:data response)))
+ "Model card should appear as a breaking entity"))))))))
+
+(deftest ^:sequential broken-entities-types-filtering-test
+ (testing "GET /api/ee/dependencies/graph/broken - types parameter filters results"
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-temp [:model/User user {:email "[email protected]"}]
+ (mt/with-model-cleanup [:model/Card :model/Dependency :model/AnalysisFinding :model/AnalysisFindingError]
+ ;; Create cards in one metadata provider cache session
+ (let [[model-card-1 model-card-2 dependent-card-1 dependent-card-2]
+ (lib-be/with-metadata-provider-cache
+ (let [model-card-1 (create-model-card! user "Model Card 1 - typesfiltertest")
+ model-card-2 (create-model-card! user "Model Card 2 - typesfiltertest")
+ dependent-card-1 (create-dependent-card-on-model! user model-card-1 "Dependent Card 1 - typesfiltertest")
+ dependent-card-2 (create-dependent-card-on-model! user model-card-2 "Dependent Card 2 - typesfiltertest")]
+ [model-card-1 model-card-2 dependent-card-1 dependent-card-2]))]
+ ;; Break both models
+ (lib-be/with-metadata-provider-cache
+ (break-model-card! model-card-1)
+ (break-model-card! model-card-2))
+ ;; Run analysis in a fresh metadata provider cache session to detect broken references
+ (lib-be/with-metadata-provider-cache
+ (while (#'dependencies.backfill/backfill-dependencies!))
+ (run-analysis-for-card! (:id dependent-card-1))
+ (run-analysis-for-card! (:id dependent-card-2)))
+ (testing "filtering by card returns only card sources"
+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&query=typesfiltertest")
+ ids (set (map :id (:data response)))]
+ (is (contains? ids (:id model-card-1)) "Model card 1 should be in results")
+ (is (contains? ids (:id model-card-2)) "Model card 2 should be in results")))
+ (testing "filtering by table returns empty (no table sources in this test)"
+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=table&query=typesfiltertest")
+ ids (set (map :id (:data response)))]
+ (is (empty? ids) "No tables should be in results")))))))))
+
+(deftest ^:sequential broken-entities-archived-card-test
+ (testing "GET /api/ee/dependencies/graph/broken with archived parameter for source cards"
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-temp [:model/User user {:email "[email protected]"}]
+ (mt/with-model-cleanup [:model/Card :model/Dependency :model/AnalysisFinding :model/AnalysisFindingError]
+ ;; Create cards in one metadata provider cache session
+ (let [[active-model archived-model dependent-card-1 dependent-card-2]
+ (lib-be/with-metadata-provider-cache
+ (let [active-model (create-model-card! user "Active Model - archivedbrokentestcard")
+ archived-model (create-model-card! user "Archived Model - archivedbrokentestcard")
+ dependent-card-1 (create-dependent-card-on-model! user active-model "Dependent of Active - archivedbrokentestcard")
+ dependent-card-2 (create-dependent-card-on-model! user archived-model "Dependent of Archived - archivedbrokentestcard")]
+ [active-model archived-model dependent-card-1 dependent-card-2]))]
+ ;; Archive the second model
+ (card/update-card! {:card-before-update archived-model
+ :card-updates {:archived true}})
+ ;; Break both models
+ (lib-be/with-metadata-provider-cache
+ (break-model-card! active-model)
+ (break-model-card! (t2/select-one :model/Card :id (:id archived-model))))
+ ;; Run analysis in a fresh metadata provider cache session to detect broken references
+ (lib-be/with-metadata-provider-cache
+ (while (#'dependencies.backfill/backfill-dependencies!))
+ (run-analysis-for-card! (:id dependent-card-1))
+ (run-analysis-for-card! (:id dependent-card-2)))
+ (testing "archived=false (default) excludes archived source card"
+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&query=archivedbrokentestcard")
+ card-ids (set (map :id (:data response)))]
+ (is (contains? card-ids (:id active-model)))
+ (is (not (contains? card-ids (:id archived-model))))))
+ (testing "archived=true includes archived source card"
+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&query=archivedbrokentestcard&archived=true")
+ card-ids (set (map :id (:data response)))]
+ (is (contains? card-ids (:id active-model)))
+ (is (contains? card-ids (:id archived-model)))))))))))
+
+(deftest ^:sequential broken-entities-multiple-dependents-test
+ (testing "GET /api/ee/dependencies/graph/broken - model breaking multiple dependents appears once"
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-temp [:model/User user {:email "[email protected]"}]
+ (mt/with-model-cleanup [:model/Card :model/Dependency :model/AnalysisFinding :model/AnalysisFindingError]
+ ;; Create cards in one metadata provider cache session
+ (let [[model-card dependent-card-1 dependent-card-2]
+ (lib-be/with-metadata-provider-cache
+ (let [model-card (create-model-card! user "Model Card - multipledependents")
+ dependent-card-1 (create-dependent-card-on-model! user model-card "Dependent 1 - multipledependents")
+ dependent-card-2 (create-dependent-card-on-model! user model-card "Dependent 2 - multipledependents")]
+ [model-card dependent-card-1 dependent-card-2]))]
+ ;; Break the model
+ (lib-be/with-metadata-provider-cache
+ (break-model-card! model-card))
+ ;; Run analysis in a fresh metadata provider cache session to detect broken references
+ (lib-be/with-metadata-provider-cache
+ (while (#'dependencies.backfill/backfill-dependencies!))
+ (run-analysis-for-card! (:id dependent-card-1))
+ (run-analysis-for-card! (:id dependent-card-2)))
+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&query=multipledependents")
+ model-ids (filter #(= (:id %) (:id model-card)) (:data response))]
+ (is (= 1 (count model-ids)) "Model should appear exactly once even with multiple broken dependents"))))))))
+
+(deftest ^:sequential broken-entities-personal-collection-card-test
+ (testing "GET /api/ee/dependencies/graph/broken with include_personal_collections parameter"
+ (mt/with-premium-features #{:dependencies}
+ (binding [collection/*allow-deleting-personal-collections* true]
+ (mt/with-temp [:model/User {user-id :id} {}
+ :model/User creator {:email "[email protected]"}
+ :model/Collection {personal-coll-id :id} {:personal_owner_id user-id
+ :name "Test Personal Collection"}]
+ (mt/with-model-cleanup [:model/Card :model/Dependency :model/AnalysisFinding :model/AnalysisFindingError]
+ ;; Create cards in one metadata provider cache session
+ (let [[model-in-personal model-regular dependent-card-1 dependent-card-2]
+ (lib-be/with-metadata-provider-cache
+ (let [model-in-personal (create-model-card! creator "Model in Personal - personalcollbrokentest"
+ :collection-id personal-coll-id)
+ model-regular (create-model-card! creator "Model Regular - personalcollbrokentest")
+ dependent-card-1 (create-dependent-card-on-model! creator model-in-personal "Dependent of Personal - personalcollbrokentest")
+ dependent-card-2 (create-dependent-card-on-model! creator model-regular "Dependent of Regular - personalcollbrokentest")]
+ [model-in-personal model-regular dependent-card-1 dependent-card-2]))]
+ ;; Break both models
+ (lib-be/with-metadata-provider-cache
+ (break-model-card! model-in-personal)
+ (break-model-card! model-regular))
+ ;; Run analysis in a fresh metadata provider cache session to detect broken references
+ (lib-be/with-metadata-provider-cache
+ (while (#'dependencies.backfill/backfill-dependencies!))
+ (run-analysis-for-card! (:id dependent-card-1))
+ (run-analysis-for-card! (:id dependent-card-2)))
+ (testing "include_personal_collections=false (default) excludes source cards in personal collections"
+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&query=personalcollbrokentest")
+ card-ids (set (map :id (:data response)))]
+ (is (not (contains? card-ids (:id model-in-personal))))
+ (is (contains? card-ids (:id model-regular)))))
+ (testing "include_personal_collections=true includes source cards in personal collections"
+ (let [response (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&query=personalcollbrokentest&include_personal_collections=true")
+ card-ids (set (map :id (:data response)))]
+ (is (contains? card-ids (:id model-in-personal)))
+ (is (contains? card-ids (:id model-regular))))))))))))
+
+(deftest ^:sequential broken-entities-pagination-test
+ (testing "GET /api/ee/dependencies/graph/broken - should paginate results"
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-temp [:model/User user {:email "[email protected]"}]
+ (mt/with-model-cleanup [:model/Card :model/Dependency :model/AnalysisFinding :model/AnalysisFindingError]
+ ;; Create cards in one metadata provider cache session
+ (let [[model-card-1 model-card-2 dependent-card-1 dependent-card-2]
+ (lib-be/with-metadata-provider-cache
+ (let [model-card-1 (create-model-card! user "A Model Card - paginationtest")
+ model-card-2 (create-model-card! user "B Model Card - paginationtest")
+ dependent-card-1 (create-dependent-card-on-model! user model-card-1 "Dependent Card 1 - paginationtest")
+ dependent-card-2 (create-dependent-card-on-model! user model-card-2 "Dependent Card 2 - paginationtest")]
+ [model-card-1 model-card-2 dependent-card-1 dependent-card-2]))]
+ ;; Break both models
+ (lib-be/with-metadata-provider-cache
+ (break-model-card! model-card-1)
+ (break-model-card! model-card-2))
+ ;; Run analysis in a fresh metadata provider cache session to detect broken references
+ (lib-be/with-metadata-provider-cache
+ (while (#'dependencies.backfill/backfill-dependencies!))
+ (run-analysis-for-card! (:id dependent-card-1))
+ (run-analysis-for-card! (:id dependent-card-2)))
+ (is (=? {:data [{:id (:id model-card-1)}]
+ :total 2
+ :offset 0
+ :limit 1}
+ (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&query=paginationtest&offset=0&limit=1")))
+ (is (=? {:data [{:id (:id model-card-2)}]
+ :total 2
+ :offset 1
+ :limit 1}
+ (mt/user-http-request :crowberto :get 200 "ee/dependencies/graph/broken?types=card&query=paginationtest&offset=1&limit=1")))))))))
+
+(deftest ^:sequential broken-entities-sort-by-name-test
(testing "GET /api/ee/dependencies/graph/broken - sorting by name"
(mt/with-premium-features #{:dependencies}
- (let [broken-query (broken-mbql-query)]
- (mt/with-temp [:model/Card _ {:name "A Card sorttest"
- :dataset_query broken-query}
- :model/Card _ {:name "B Card sorttest"
- :dataset_query broken-query}]
- (while (> (dependencies.findings/analyze-batch! :card 50) 0))
- (doseq [sort-direction [:asc :desc]]
- (let [response (mt/user-http-request :crowberto :get 200
- "ee/dependencies/graph/broken"
- :query "sorttest"
- :sort_column :name
- :sort_direction sort-direction)
- names (mapv #(get-in % [:data :name]) (:data response))]
- (is (= (cond-> ["A Card sorttest"
- "B Card sorttest"]
- (= sort-direction :desc) reverse)
- names)))))))))
-
-(deftest ^:sequential broken-sort-by-location-test
+ (mt/with-temp [:model/User user {:email "[email protected]"}]
+ (mt/with-model-cleanup [:model/Card :model/Dependency :model/AnalysisFinding :model/AnalysisFindingError]
+ ;; Create cards in one metadata provider cache session
+ (let [[model-card-a model-card-b dependent-card-a dependent-card-b]
+ (lib-be/with-metadata-provider-cache
+ (let [model-card-a (create-model-card! user "A Card sortnametest")
+ model-card-b (create-model-card! user "B Card sortnametest")
+ dependent-card-a (create-dependent-card-on-model! user model-card-a "Dependent A - sortnametest")
+ dependent-card-b (create-dependent-card-on-model! user model-card-b "Dependent B - sortnametest")]
+ [model-card-a model-card-b dependent-card-a dependent-card-b]))]
+ ;; Break both models
+ (lib-be/with-metadata-provider-cache
+ (break-model-card! model-card-a)
+ (break-model-card! model-card-b))
+ ;; Run analysis in a fresh metadata provider cache session to detect broken references
+ (lib-be/with-metadata-provider-cache
+ (while (#'dependencies.backfill/backfill-dependencies!))
+ (run-analysis-for-card! (:id dependent-card-a))
+ (run-analysis-for-card! (:id dependent-card-b)))
+ (doseq [sort-direction [:asc :desc]]
+ (let [response (mt/user-http-request :crowberto :get 200
+ "ee/dependencies/graph/broken"
+ :types "card"
+ :query "sortnametest"
+ :sort_column :name
+ :sort_direction sort-direction)
+ names (mapv #(get-in % [:data :name]) (:data response))]
+ (is (= (cond-> ["A Card sortnametest"
+ "B Card sortnametest"]
+ (= sort-direction :desc) reverse)
+ names))))))))))
+
+(deftest ^:sequential broken-entities-sort-by-location-test
(testing "GET /api/ee/dependencies/graph/broken - sorting by location"
(mt/with-premium-features #{:dependencies}
- (let [broken-query (broken-mbql-query)]
- (mt/with-temp [:model/Collection {collection1-id :id} {:name "B Collection"}
- :model/Collection {collection2-id :id} {:name "A Collection"}
- :model/Card _ {:name "Card with Collection 1 sorttest"
- :dataset_query broken-query
- :collection_id collection1-id}
- :model/Card _ {:name "Card with Collection 2 sorttest"
- :dataset_query broken-query
- :collection_id collection2-id}]
- (while (> (dependencies.findings/analyze-batch! :card 50) 0))
- (doseq [sort-direction [:asc :desc]]
- (let [response (mt/user-http-request :crowberto :get 200
- "ee/dependencies/graph/broken"
- :query "sorttest"
- :sort_column :location
- :sort_direction sort-direction)
- names (mapv #(get-in % [:data :name]) (:data response))]
- (is (= (cond-> ["Card with Collection 2 sorttest"
- "Card with Collection 1 sorttest"]
- (= sort-direction :desc) reverse)
- names)))))))))
-
-(deftest ^:sequential broken-sort-by-dependents-count-test
- (testing "GET /api/ee/dependencies/graph/broken - sorting by dependents count"
+ (mt/with-temp [:model/User user {:email "[email protected]"}
+ :model/Collection {collection1-id :id} {:name "B Collection"}
+ :model/Collection {collection2-id :id} {:name "A Collection"}]
+ (mt/with-model-cleanup [:model/Card :model/Dependency :model/AnalysisFinding :model/AnalysisFindingError]
+ ;; Create cards in one metadata provider cache session
+ (let [[model-in-coll1 model-in-coll2 dependent-card-1 dependent-card-2]
+ (lib-be/with-metadata-provider-cache
+ (let [model-in-coll1 (create-model-card! user "Card with Collection 1 sortloctest" :collection-id collection1-id)
+ model-in-coll2 (create-model-card! user "Card with Collection 2 sortloctest" :collection-id collection2-id)
+ dependent-card-1 (create-dependent-card-on-model! user model-in-coll1 "Dependent of Coll1 - sortloctest")
+ dependent-card-2 (create-dependent-card-on-model! user model-in-coll2 "Dependent of Coll2 - sortloctest")]
+ [model-in-coll1 model-in-coll2 dependent-card-1 dependent-card-2]))]
+ ;; Break both models
+ (lib-be/with-metadata-provider-cache
+ (break-model-card! model-in-coll1)
+ (break-model-card! model-in-coll2))
+ ;; Run analysis in a fresh metadata provider cache session to detect broken references
+ (lib-be/with-metadata-provider-cache
+ (while (#'dependencies.backfill/backfill-dependencies!))
+ (run-analysis-for-card! (:id dependent-card-1))
+ (run-analysis-for-card! (:id dependent-card-2)))
+ (doseq [sort-direction [:asc :desc]]
+ (let [response (mt/user-http-request :crowberto :get 200
+ "ee/dependencies/graph/broken"
+ :types "card"
+ :query "sortloctest"
+ :sort_column :location
+ :sort_direction sort-direction)
+ names (mapv #(get-in % [:data :name]) (:data response))]
+ (is (= (cond-> ["Card with Collection 2 sortloctest"
+ "Card with Collection 1 sortloctest"]
+ (= sort-direction :desc) reverse)
+ names))))))))))
+
+(deftest ^:sequential broken-entities-sort-by-dependents-with-errors-count-test
+ (testing "GET /api/ee/dependencies/graph/broken - sorting by dependents with errors count"
(mt/with-premium-features #{:dependencies}
- (let [broken-query (broken-mbql-query)]
- (mt/with-temp [:model/Card card1 {:name "Card 1 sorttest"
- :dataset_query broken-query}
- :model/Card card2 {:name "Card 2 sorttest"
- :dataset_query broken-query}
- :model/Card _ {:name "Card 1.1 sorttest"
- :dataset_query (wrap-card-query card1)}
- :model/Card _ {:name "Card 1.2 sorttest"
- :dataset_query (wrap-card-query card1)}
- :model/Card _ {:name "Card 2.1 sorttest"
- :dataset_query (wrap-card-query card2)}]
- (while (#'dependencies.backfill/backfill-dependencies!))
- (while (> (dependencies.findings/analyze-batch! :card 50) 0))
- (doseq [sort-direction [:asc :desc]]
- (let [response (mt/user-http-request :crowberto :get 200
- "ee/dependencies/graph/broken"
- :query "sorttest"
- :sort_column :dependents-count
- :sort_direction sort-direction)
- names (mapv #(get-in % [:data :name]) (:data response))]
- (is (= (cond-> ["Card 2 sorttest"
- "Card 1 sorttest"]
- (= sort-direction :desc) reverse)
- names)))))))))
+ (mt/with-temp [:model/User user {:email "[email protected]"}]
+ (mt/with-model-cleanup [:model/Card :model/Dependency :model/AnalysisFinding :model/AnalysisFindingError]
+ ;; Create cards in one metadata provider cache session
+ (let [[model-card-1 model-card-2 dependent-card-1a dependent-card-1b dependent-card-2a]
+ (lib-be/with-metadata-provider-cache
+ (let [model-card-1 (create-model-card! user "Card 1 sortdepstest")
+ model-card-2 (create-model-card! user "Card 2 sortdepstest")
+ ;; Model 1 has 2 dependents, Model 2 has 1 dependent
+ dependent-card-1a (create-dependent-card-on-model! user model-card-1 "Dependent 1a - sortdepstest")
+ dependent-card-1b (create-dependent-card-on-model! user model-card-1 "Dependent 1b - sortdepstest")
+ dependent-card-2a (create-dependent-card-on-model! user model-card-2 "Dependent 2a - sortdepstest")]
+ [model-card-1 model-card-2 dependent-card-1a dependent-card-1b dependent-card-2a]))]
+ ;; Break both models
+ (lib-be/with-metadata-provider-cache
+ (break-model-card! model-card-1)
+ (break-model-card! model-card-2))
+ ;; Run analysis in a fresh metadata provider cache session to detect broken references
+ (lib-be/with-metadata-provider-cache
+ (while (#'dependencies.backfill/backfill-dependencies!))
+ (run-analysis-for-card! (:id dependent-card-1a))
+ (run-analysis-for-card! (:id dependent-card-1b))
+ (run-analysis-for-card! (:id dependent-card-2a)))
+ (doseq [sort-direction [:asc :desc]]
+ (let [response (mt/user-http-request :crowberto :get 200
+ "ee/dependencies/graph/broken"
+ :types "card"
+ :query "sortdepstest"
+ :sort_column :dependents-with-errors
+ :sort_direction sort-direction)
+ names (mapv #(get-in % [:data :name]) (:data response))]
+ (is (= (cond-> ["Card 2 sortdepstest"
+ "Card 1 sortdepstest"]
+ (= sort-direction :desc) reverse)
+ names))))))))))
+
+(deftest ^:sequential broken-entities-sort-by-dependents-with-errors-test
+ (testing "GET /api/ee/dependencies/graph/broken - sorting by dependents with errors count"
+ (mt/with-premium-features #{:dependencies}
+ (mt/with-temp [:model/User user {:email "[email protected]"}]
+ (mt/with-model-cleanup [:model/Card :model/Dependency :model/AnalysisFinding :model/AnalysisFindingError]
+ ;; Create cards in one metadata provider cache session
+ ;; Model 1 breaks 2 dependent cards (2 unique analyzed entities with errors)
+ ;; Model 2 breaks 1 dependent card (1 unique analyzed entity with errors)
+ (let [[model-card-1 model-card-2 dependent-card-1a dependent-card-1b dependent-card-2a]
+ (lib-be/with-metadata-provider-cache
+ (let [model-card-1 (create-model-card! user "Card 1 sorterrorstest")
+ model-card-2 (create-model-card! user "Card 2 sorterrorstest")
+ dependent-card-1a (create-dependent-card-on-model! user model-card-1 "Dependent 1a - sorterrorstest")
+ dependent-card-1b (create-dependent-card-on-model! user model-card-1 "Dependent 1b - sorterrorstest")
+ dependent-card-2a (create-dependent-card-on-model! user model-card-2 "Dependent 2a - sorterrorstest")]
+ [model-card-1 model-card-2 dependent-card-1a dependent-card-1b dependent-card-2a]))]
+ ;; Break both models
+ (lib-be/with-metadata-provider-cache
+ (break-model-card! model-card-1)
+ (break-model-card! model-card-2))
+ ;; Run analysis in a fresh metadata provider cache session to detect broken references
+ (lib-be/with-metadata-provider-cache
+ (while (#'dependencies.backfill/backfill-dependencies!))
+ (run-analysis-for-card! (:id dependent-card-1a))
+ (run-analysis-for-card! (:id dependent-card-1b))
+ (run-analysis-for-card! (:id dependent-card-2a)))
+ (doseq [sort-direction [:asc :desc]]
+ (let [response (mt/user-http-request :crowberto :get 200
+ "ee/dependencies/graph/broken"
+ :types "card"
+ :query "sorterrorstest"
+ :sort_column :dependents-with-errors
+ :sort_direction sort-direction)
+ names (mapv #(get-in % [:data :name]) (:data response))]
+ ;; Card 2 has 1 broken dependent, Card 1 has 2 broken dependents
+ ;; Ascending: fewer errors first, Descending: more errors first
+ (is (= (cond-> ["Card 2 sorterrorstest"
+ "Card 1 sorterrorstest"]
+ (= sort-direction :desc) reverse)
+ names))))))))))
diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/core_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/core_test.clj
index 34bdf0ab942..ee1cb4410ff 100644
--- a/enterprise/backend/test/metabase_enterprise/dependencies/core_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/dependencies/core_test.clj
@@ -145,11 +145,11 @@
errors (dependencies/errors-from-proposed-edits {:card [card']}
:base-provider provider
:graph graph)]
- (is (=? {:card {downstream-card-id #{{:type :validate/missing-column
+ (is (=? {:card {downstream-card-id #{{:type :missing-column
:name "Tax Rate"
:source-entity-type :card
:source-entity-id 101}}
- transformed-card-id #{{:type :validate/missing-column
+ transformed-card-id #{{:type :missing-column
:name "Tax Rate"
:source-entity-type :table
:source-entity-id 1234567}}}}
@@ -182,7 +182,7 @@
;; queries that consume the transform's table.
(is (=? {:card {direct-sql-card-id #{(lib/missing-table-alias-error "NONEXISTENT_TABLE")}
transformed-sql-card-id #{(lib/missing-table-alias-error "TRANSFORMED.OUTPUT_TF31")}
- transformed-mbql-card-id #{{:type :validate/missing-column
+ transformed-mbql-card-id #{{:type :missing-column
:name "RATING"
:source-entity-type :table
:source-entity-id 1234568}}}
diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/events_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/events_test.clj
index 93a4f365713..081d11a7bf7 100644
--- a/enterprise/backend/test/metabase_enterprise/dependencies/events_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/dependencies/events_test.clj
@@ -606,7 +606,8 @@
Use nil for analysis-version if you want to check that no analysis exists."
[spec]
(doseq [[entity-type ids-and-versions] spec]
- (let [analyses-map (->> (t2/select [:model/AnalysisFinding :analyzed_entity_id :analysis_version])
+ (let [analyses-map (->> (t2/select [:model/AnalysisFinding :analyzed_entity_id :analysis_version]
+ :analyzed_entity_type entity-type)
(into {} (map (juxt :analyzed_entity_id :analysis_version))))]
(doseq [[id expected-version] ids-and-versions]
(testing (str "Checking " entity-type " " id)
diff --git a/enterprise/backend/test/metabase_enterprise/dependencies/models/analysis_finding_error_test.clj b/enterprise/backend/test/metabase_enterprise/dependencies/models/analysis_finding_error_test.clj
index 648db911f65..544e1de53ba 100644
--- a/enterprise/backend/test/metabase_enterprise/dependencies/models/analysis_finding_error_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/dependencies/models/analysis_finding_error_test.clj
@@ -9,11 +9,11 @@
(mt/with-premium-features #{:dependencies}
(testing "Can insert errors for an entity"
(mt/with-empty-h2-app-db!
- (let [errors [{:error-type :validate/missing-column
+ (let [errors [{:error-type :missing-column
:error-detail "CATEGORY"
:source-entity-type :table
:source-entity-id 100}
- {:error-type :validate/missing-column
+ {:error-type :missing-column
:error-detail "PRICE"
:source-entity-type :table
:source-entity-id 100}]]
@@ -22,17 +22,17 @@
:analyzed_entity_type :card
:analyzed_entity_id 1)]
(is (= 2 (count stored)))
- (is (= #{:validate/missing-column} (set (map :error_type stored))))
+ (is (= #{:missing-column} (set (map :error_type stored))))
(is (= #{"CATEGORY" "PRICE"} (set (map :error_detail stored))))
(is (= #{:table} (set (map :source_entity_type stored))))
(is (= #{100} (set (map :source_entity_id stored))))))))
(testing "Replaces existing errors when called again"
(mt/with-empty-h2-app-db!
- (let [old-errors [{:error-type :validate/missing-column
+ (let [old-errors [{:error-type :missing-column
:error-detail "OLD_COLUMN"
:source-entity-type :table
:source-entity-id 100}]
- new-errors [{:error-type :validate/syntax-error
+ new-errors [{:error-type :syntax-error
:error-detail nil
:source-entity-type nil
:source-entity-id nil}]]
@@ -44,13 +44,13 @@
(let [stored (t2/select-one :model/AnalysisFindingError
:analyzed_entity_type :card
:analyzed_entity_id 1)]
- (is (= :validate/syntax-error (:error_type stored)))
+ (is (= :syntax-error (:error_type stored)))
(is (nil? (:error_detail stored)))
(is (nil? (:source_entity_type stored)))
(is (nil? (:source_entity_id stored)))))))
(testing "Clears errors when passed empty list"
(mt/with-empty-h2-app-db!
- (let [errors [{:error-type :validate/missing-column
+ (let [errors [{:error-type :missing-column
:error-detail "CATEGORY"
:source-entity-type :table
:source-entity-id 100}]]
@@ -68,15 +68,15 @@
(mt/with-premium-features #{:dependencies}
(mt/with-empty-h2-app-db!
(testing "Can query errors by source entity"
- (let [errors-card-1 [{:error-type :validate/missing-column
+ (let [errors-card-1 [{:error-type :missing-column
:error-detail "CATEGORY"
:source-entity-type :table
:source-entity-id 100}]
- errors-card-2 [{:error-type :validate/missing-column
+ errors-card-2 [{:error-type :missing-column
:error-detail "PRICE"
:source-entity-type :table
:source-entity-id 100}
- {:error-type :validate/missing-column
+ {:error-type :missing-column
:error-detail "NAME"
:source-entity-type :table
:source-entity-id 200}]]
@@ -93,11 +93,11 @@
(mt/with-premium-features #{:dependencies}
(mt/with-empty-h2-app-db!
(testing "Can query all errors for a specific entity"
- (let [errors [{:error-type :validate/missing-column
+ (let [errors [{:error-type :missing-column
:error-detail "CATEGORY"
:source-entity-type :table
:source-entity-id 100}
- {:error-type :validate/missing-column
+ {:error-type :missing-column
:error-detail "PRICE"
:source-entity-type :card
:source-entity-id 50}]]
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsx
index 0023b1f90b3..ff6ec909921 100644
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsx
@@ -5,7 +5,6 @@ import { t } from "ttag";
import DataStudioLogo from "assets/img/data-studio-logo.svg";
import { ForwardRefLink } from "metabase/common/components/Link";
import { useUserKeyValue } from "metabase/common/hooks/use-user-key-value";
-import { isCypressActive } from "metabase/env";
import { isMac } from "metabase/lib/browser";
import { useSelector } from "metabase/lib/redux";
import * as Urls from "metabase/lib/urls";
@@ -147,8 +146,7 @@ function DataStudioNav({ isNavbarOpened, onNavbarToggle }: DataStudioNavProps) {
showLabel={isNavbarOpened}
/>
)}
- {/* TODO (Alex P 01/15/2026): remove isCypressActive once we are ready to release this feature */}
- {PLUGIN_DEPENDENCIES.isEnabled && isCypressActive && (
+ {PLUGIN_DEPENDENCIES.isEnabled && (
<DataStudioTab
label={t`Dependency diagnostics`}
icon="list"
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/PanelBody.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/PanelBody.tsx
index fd977eb5f9b..29aa33b7220 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/PanelBody.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/PanelBody.tsx
@@ -10,13 +10,13 @@ import {
getNodeLink,
getNodeLocationInfo,
getNodeViewCount,
+ getNodeViewCountLabel,
} from "../../../../utils";
import { GraphBreadcrumbs } from "../../GraphBreadcrumbs";
import { GraphExternalLink } from "../../GraphExternalLink";
import { GraphLink } from "../../GraphLink";
import S from "./PanelBody.module.css";
-import { getNodeViewCountLabel } from "./utils";
type PanelBodyProps = {
nodes: DependencyNode[];
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/utils.ts
deleted file mode 100644
index 6eec4fcfd51..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/PanelBody/utils.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { msgid, ngettext } from "ttag";
-
-export function getNodeViewCountLabel(viewCount: number) {
- return ngettext(msgid`${viewCount} view`, `${viewCount} views`, viewCount);
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/utils.ts
index 9bd7f325731..e06f305be9d 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyGraph/GraphDependencyPanel/utils.ts
@@ -26,11 +26,14 @@ export function getListRequest(
node: DependencyNode,
groupType: DependencyGroupType,
): ListNodeDependentsRequest {
+ const type = getDependencyType(groupType);
+ const cardType = getCardType(groupType);
+
return {
id: node.id,
type: node.type,
- dependent_type: getDependencyType(groupType),
- dependent_card_type: getCardType(groupType) ?? undefined,
+ dependent_types: [type],
+ dependent_card_types: cardType != null ? [cardType] : undefined,
};
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsx
index 736def443d6..c36f18a04ca 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/DependencyList.tsx
@@ -1,4 +1,4 @@
-import { useState } from "react";
+import { useLayoutEffect, useState } from "react";
import { DelayedLoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper/DelayedLoadingAndErrorWrapper";
import type * as Urls from "metabase/lib/urls";
@@ -75,6 +75,12 @@ export function DependencyList({
onParamsChange({ ...params, sorting });
};
+ useLayoutEffect(() => {
+ if (selectedEntry != null && selectedNode == null) {
+ setSelectedEntry(undefined);
+ }
+ }, [selectedEntry, selectedNode]);
+
return (
<Flex h="100%">
<Stack className={S.main} flex={1} px="3.5rem" pb="md" gap="md">
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/ErrorsCell/ErrorsCell.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/ErrorsCell/ErrorsCell.tsx
index 900c78b2020..2e3f8460f4d 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/ErrorsCell/ErrorsCell.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/ErrorsCell/ErrorsCell.tsx
@@ -1,14 +1,14 @@
import { Ellipsified } from "metabase/common/components/Ellipsified";
import type { DependencyNode } from "metabase-types/api";
-import { getDependencyErrorInfo } from "../../../../utils";
+import { getDependencyErrorInfo, getDependencyErrors } from "../../../../utils";
type ErrorsCellProps = {
node: DependencyNode;
};
export function ErrorsCell({ node }: ErrorsCellProps) {
- const errors = node.dependents_errors ?? [];
+ const errors = getDependencyErrors(node.dependents_errors ?? []);
const errorsInfo = getDependencyErrorInfo(errors);
if (!errorsInfo) {
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/utils.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/utils.tsx
index 010e769573a..441a6fc9af5 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/utils.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListBody/utils.tsx
@@ -2,14 +2,15 @@ import type { SortingState } from "@tanstack/react-table";
import { t } from "ttag";
import type { TreeTableColumnDef } from "metabase/ui";
-import type {
- DependencyNode,
- DependencySortColumn,
- DependencySortingOptions,
+import {
+ DEPENDENCY_SORT_COLUMNS,
+ type DependencyNode,
+ type DependencySortColumn,
+ type DependencySortingOptions,
} from "metabase-types/api";
import {
- getNodeDependentsCount,
+ getDependentErrorNodesCount,
getNodeLabel,
getNodeLocationInfo,
} from "../../../utils";
@@ -19,11 +20,11 @@ import { ErrorsCell } from "./ErrorsCell";
import { LocationCell } from "./LocationCell";
import { NameCell } from "./NameCell";
-function getNodeNameColumn(
+function getNameColumn(
mode: DependencyListMode,
): TreeTableColumnDef<DependencyNode> {
return {
- id: "name",
+ id: "name" satisfies DependencySortColumn,
header: mode === "broken" ? t`Dependency` : t`Name`,
minWidth: 100,
enableSorting: true,
@@ -35,9 +36,9 @@ function getNodeNameColumn(
};
}
-function getNodeLocationColumn(): TreeTableColumnDef<DependencyNode> {
+function getLocationColumn(): TreeTableColumnDef<DependencyNode> {
return {
- id: "location",
+ id: "location" satisfies DependencySortColumn,
header: t`Location`,
minWidth: 100,
enableSorting: true,
@@ -53,12 +54,12 @@ function getNodeLocationColumn(): TreeTableColumnDef<DependencyNode> {
};
}
-function getNodeErrorsColumn(): TreeTableColumnDef<DependencyNode> {
+function getDependentsErrorsColumn(): TreeTableColumnDef<DependencyNode> {
return {
- id: "dependents-errors",
+ id: "dependents-errors" satisfies DependencySortColumn,
header: t`Problems`,
minWidth: 100,
- enableSorting: false,
+ enableSorting: true,
accessorFn: (node) => node.dependents_errors?.length ?? 0,
cell: ({ row }) => {
const node = row.original;
@@ -71,16 +72,17 @@ function getNodeErrorsColumn(): TreeTableColumnDef<DependencyNode> {
};
}
-function getNodeDependentsCountColumn(): TreeTableColumnDef<DependencyNode> {
+function getDependentsWithErrorsColumn(): TreeTableColumnDef<DependencyNode> {
return {
- id: "dependents-count",
- header: t`Dependents`,
+ id: "dependents-with-errors" satisfies DependencySortColumn,
+ header: t`Broken dependents`,
minWidth: 100,
enableSorting: true,
- accessorFn: (node) => getNodeDependentsCount(node),
+ accessorFn: (node) =>
+ getDependentErrorNodesCount(node.dependents_errors ?? []),
cell: ({ row }) => {
const node = row.original;
- return getNodeDependentsCount(node);
+ return getDependentErrorNodesCount(node.dependents_errors ?? []);
},
};
}
@@ -89,10 +91,10 @@ export function getColumns(
mode: DependencyListMode,
): TreeTableColumnDef<DependencyNode>[] {
return [
- getNodeNameColumn(mode),
- getNodeLocationColumn(),
- ...(mode === "broken" ? [getNodeErrorsColumn()] : []),
- ...(mode === "broken" ? [getNodeDependentsCountColumn()] : []),
+ getNameColumn(mode),
+ getLocationColumn(),
+ ...(mode === "broken" ? [getDependentsErrorsColumn()] : []),
+ ...(mode === "broken" ? [getDependentsWithErrorsColumn()] : []),
];
}
@@ -118,9 +120,15 @@ export function getSortingOptions(
if (sortingState.length === 0) {
return undefined;
}
+
const { id, desc } = sortingState[0];
+ const column = DEPENDENCY_SORT_COLUMNS.find((column) => column === id);
+ if (column == null) {
+ return undefined;
+ }
+
return {
- column: id as DependencySortColumn,
+ column,
direction: desc ? "desc" : "asc",
};
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListHeader/ListHeader.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListHeader/ListHeader.tsx
index b7b4e8eae51..dfe042dedaa 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListHeader/ListHeader.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListHeader/ListHeader.tsx
@@ -14,12 +14,12 @@ export const ListHeader = memo(function ListHeader() {
{
label: t`Broken dependencies`,
to: Urls.brokenDependencies(),
- icon: "list",
+ icon: "broken_link",
},
{
label: t`Unreferenced entities`,
to: Urls.unreferencedDependencies(),
- icon: "list",
+ icon: "unreferenced",
},
];
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/ListSearchBar.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/ListSearchBar.tsx
index 25735822517..0f83178706c 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/ListSearchBar.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSearchBar/ListSearchBar.tsx
@@ -4,7 +4,7 @@ import { t } from "ttag";
import { SEARCH_DEBOUNCE_DURATION } from "metabase/lib/constants";
import type * as Urls from "metabase/lib/urls";
-import { Flex, Icon, Loader, TextInput } from "metabase/ui";
+import { FixedSizeIcon, Flex, Loader, TextInput } from "metabase/ui";
import { getSearchQuery } from "../../../utils";
import type { DependencyListMode } from "../types";
@@ -46,7 +46,7 @@ export const ListSearchBar = memo(function ListSearchBar({
value={searchValue}
placeholder={t`Search…`}
flex={1}
- leftSection={<Icon name="search" />}
+ leftSection={<FixedSizeIcon name="search" />}
rightSection={hasLoader ? <Loader size="sm" /> : undefined}
data-testid="dependency-list-search-input"
onChange={handleSearchChange}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.module.css b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.module.css
index 7b441d75e53..9f1c9cd59db 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.module.css
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.module.css
@@ -1,4 +1,19 @@
-.panel {
+.sidebar {
overflow: auto;
border-left: 1px solid var(--mb-color-border);
}
+
+.link {
+ color: var(--mb-color-text-primary);
+
+ &:hover {
+ color: var(--mb-color-brand);
+ text-decoration: none;
+ }
+}
+
+.section {
+ &:not(:last-child) {
+ border-bottom: 1px solid var(--mb-color-border);
+ }
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.tsx
index 6bf93ae6241..b9c37db84e5 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/ListSidebar.tsx
@@ -3,13 +3,15 @@ import { memo } from "react";
import { Stack } from "metabase/ui";
import type { DependencyNode } from "metabase-types/api";
+import { getDependencyErrorGroups, getDependencyErrors } from "../../../utils";
+
import S from "./ListSidebar.module.css";
import { SidebarCreationInfo } from "./SidebarCreationInfo";
import { SidebarDependentsInfo } from "./SidebarDependentsInfo";
import { SidebarErrorInfo } from "./SidebarErrorInfo";
import { SidebarHeader } from "./SidebarHeader";
import { SidebarLocationInfo } from "./SidebarLocationInfo";
-import { getDependencyErrorGroups } from "./utils";
+import { SidebarTransformInfo } from "./SidebarTransformInfo";
type ListSidebarProps = {
node: DependencyNode;
@@ -20,20 +22,24 @@ export const ListSidebar = memo(function ListSidebar({
node,
onClose,
}: ListSidebarProps) {
- const errorGroups = getDependencyErrorGroups(node.dependents_errors ?? []);
+ const errors = getDependencyErrors(node.dependents_errors ?? []);
+ const errorGroups = getDependencyErrorGroups(errors);
return (
<Stack
- className={S.panel}
+ className={S.sidebar}
p="lg"
- w="25rem"
- gap="lg"
+ w="32rem"
+ gap="xl"
+ bg="background-primary"
data-testid="dependency-list-sidebar"
>
- <SidebarHeader node={node} onClose={onClose} />
- <SidebarCreationInfo node={node} />
- <SidebarLocationInfo node={node} />
- <SidebarDependentsInfo node={node} />
+ <Stack gap="lg">
+ <SidebarHeader node={node} onClose={onClose} />
+ <SidebarLocationInfo node={node} />
+ <SidebarTransformInfo node={node} />
+ <SidebarCreationInfo node={node} />
+ </Stack>
{errorGroups.map((errorGroup) => (
<SidebarErrorInfo
key={errorGroup.type}
@@ -41,6 +47,7 @@ export const ListSidebar = memo(function ListSidebar({
errors={errorGroup.errors}
/>
))}
+ <SidebarDependentsInfo node={node} />
</Stack>
);
});
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarCreationInfo/SidebarCreationInfo.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarCreationInfo/SidebarCreationInfo.tsx
index 81ef1aa263f..77e2986c1e6 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarCreationInfo/SidebarCreationInfo.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarCreationInfo/SidebarCreationInfo.tsx
@@ -1,7 +1,9 @@
import { t } from "ttag";
-import { EntityCreationInfo } from "metabase/common/components/EntityCreationInfo";
-import { Card, Stack, Title } from "metabase/ui";
+import DateTime from "metabase/common/components/DateTime";
+import CS from "metabase/css/core/index.css";
+import { getUserName } from "metabase/lib/user";
+import { Box, Card, Group, Stack } from "metabase/ui";
import type { DependencyNode } from "metabase-types/api";
import {
@@ -10,36 +12,68 @@ import {
getNodeLastEditedAt,
getNodeLastEditedBy,
} from "../../../../utils";
+import S from "../ListSidebar.module.css";
type SidebarCreationInfoProps = {
node: DependencyNode;
};
export function SidebarCreationInfo({ node }: SidebarCreationInfoProps) {
- const title = t`Creator and last editor`;
- const createdAt = getNodeCreatedAt(node);
const createdBy = getNodeCreatedBy(node);
- const editedAt = getNodeLastEditedAt(node);
+ const createdAt = getNodeCreatedAt(node);
const editedBy = getNodeLastEditedBy(node);
- const hasCreatedInfo = createdAt != null && createdBy != null;
- const hasEditedInfo = editedAt != null && editedBy != null;
+ const editedAt = getNodeLastEditedAt(node);
+ const hasCreatedInfo = createdBy != null && createdAt != null;
+ const hasEditedInfo = editedBy != null && editedAt != null;
if (!hasCreatedInfo && !hasEditedInfo) {
return null;
}
return (
- <Stack gap="sm" role="region" aria-label={title}>
- <Title order={4}>{title}</Title>
- <Card p="md" shadow="none" withBorder>
- <EntityCreationInfo
- createdAt={createdAt}
- creator={createdBy}
- lastEditedAt={editedAt}
- lastEditor={editedBy}
- withTitle={false}
+ <Card
+ p={0}
+ shadow="none"
+ withBorder
+ role="region"
+ aria-label={t`Creator and last editor`}
+ >
+ {createdBy != null && createdAt != null && (
+ <UserSection
+ label={t`Created by`}
+ name={getUserName(createdBy)}
+ date={createdAt}
+ />
+ )}
+ {editedBy != null && editedAt != null && (
+ <UserSection
+ label={t`Last edited by`}
+ name={getUserName(editedBy)}
+ date={editedAt}
/>
- </Card>
+ )}
+ </Card>
+ );
+}
+
+type UserSectionProps = {
+ label: string;
+ name: string | undefined;
+ date: string;
+};
+
+function UserSection({ label, name, date }: UserSectionProps) {
+ return (
+ <Stack className={S.section} c="text-secondary" p="md" gap="xs">
+ <Box className={CS.textWrap} fz="sm" lh="h5">
+ {label}
+ </Box>
+ <Group lh="h4" justify="space-between" wrap="nowrap">
+ <Box className={CS.textWrap} c="text-primary">
+ {name}
+ </Box>
+ <DateTime value={date} unit="day" />
+ </Group>
</Stack>
);
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsInfo/SidebarDependentsInfo.module.css b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsInfo/SidebarDependentsInfo.module.css
new file mode 100644
index 00000000000..06edbfd453d
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsInfo/SidebarDependentsInfo.module.css
@@ -0,0 +1,12 @@
+.item {
+ cursor: pointer;
+
+ &:hover,
+ &.active {
+ background-color: var(--mb-color-background-secondary);
+ }
+
+ &:not(:last-child) {
+ border-bottom: 1px solid var(--mb-color-border);
+ }
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsInfo/SidebarDependentsInfo.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsInfo/SidebarDependentsInfo.tsx
index 48b7dff4ef2..f68324403e2 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsInfo/SidebarDependentsInfo.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarDependentsInfo/SidebarDependentsInfo.tsx
@@ -1,48 +1,147 @@
+import cx from "classnames";
+import { useState } from "react";
+import { t } from "ttag";
+
import { ForwardRefLink } from "metabase/common/components/Link";
+import CS from "metabase/css/core/index.css";
import * as Urls from "metabase/lib/urls";
-import { Anchor, Card, Group, Icon, Stack, Title } from "metabase/ui";
+import {
+ Badge,
+ Box,
+ Breadcrumbs,
+ Card,
+ FixedSizeIcon,
+ Group,
+ Menu,
+ Stack,
+ Title,
+} from "metabase/ui";
+import { useListNodeDependentsQuery } from "metabase-enterprise/api";
import type { DependencyNode } from "metabase-types/api";
import {
- getDependencyGroupIcon,
- getDependencyGroupTitle,
- getDependentGroupLabel,
- getDependentGroups,
+ getDependentErrorNodesCount,
+ getDependentErrorNodesLabel,
+ getNodeIcon,
+ getNodeLabel,
+ getNodeLink,
+ getNodeLocationInfo,
+ getNodeViewCount,
+ getNodeViewCountLabel,
} from "../../../../utils";
+import S from "./SidebarDependentsInfo.module.css";
+
type SidebarDependentsInfoProps = {
node: DependencyNode;
};
export function SidebarDependentsInfo({ node }: SidebarDependentsInfoProps) {
- const groups = getDependentGroups(node);
- const title = getDependencyGroupTitle(node, groups);
- const link = Urls.dependencyGraph({ entry: node });
+ const count = getDependentErrorNodesCount(node.dependents_errors ?? []);
+ const title = getDependentErrorNodesLabel(count);
+
+ const { data: dependents = [] } = useListNodeDependentsQuery(
+ {
+ id: node.id,
+ type: node.type,
+ broken: true,
+ },
+ {
+ skip: count === 0,
+ },
+ );
- if (groups.length === 0) {
+ if (count === 0) {
return null;
}
return (
- <Stack gap="sm" role="region" aria-label={title}>
- <Title order={4}>{title}</Title>
- <Card shadow="none" withBorder>
- <Stack gap="sm" lh="1rem">
- {groups.map((group, groupIndex) => (
- <Anchor
- key={groupIndex}
- component={ForwardRefLink}
- to={link}
- target="_blank"
- >
- <Group gap="sm" wrap="nowrap">
- <Icon name={getDependencyGroupIcon(group.type)} />
- {getDependentGroupLabel(group)}
- </Group>
- </Anchor>
+ <Stack role="region" aria-label={getDependentErrorNodesLabel()}>
+ <Group gap="sm">
+ <Badge c="text-selected" bg="error">
+ {count}
+ </Badge>
+ <Title order={5}>{title}</Title>
+ </Group>
+ {dependents.length > 0 && (
+ <Card p={0} shadow="none" withBorder>
+ {dependents.map((dependent, dependentIndex) => (
+ <DependentItem key={dependentIndex} node={dependent} />
))}
- </Stack>
- </Card>
+ </Card>
+ )}
</Stack>
);
}
+
+type DependentItemProps = {
+ node: DependencyNode;
+};
+
+function DependentItem({ node }: DependentItemProps) {
+ const [isOpened, setIsOpened] = useState(false);
+ const label = getNodeLabel(node);
+ const link = getNodeLink(node);
+ const icon = getNodeIcon(node);
+ const location = getNodeLocationInfo(node);
+ const viewCount = getNodeViewCount(node);
+
+ return (
+ <Menu opened={isOpened} onChange={setIsOpened}>
+ <Menu.Target>
+ <Stack
+ className={cx(S.item, { [S.active]: isOpened })}
+ p="md"
+ gap="sm"
+ aria-label={label}
+ >
+ <Group gap="sm" justify="space-between" wrap="nowrap">
+ <Group gap="sm" wrap="nowrap">
+ <FixedSizeIcon name={icon} />
+ <Box className={CS.textWrap} lh="1rem">
+ {label}
+ </Box>
+ </Group>
+ {viewCount != null && (
+ <Box c="text-secondary" fz="sm" lh="1rem">
+ {getNodeViewCountLabel(viewCount)}
+ </Box>
+ )}
+ </Group>
+ {location != null && (
+ <Breadcrumbs
+ separator={<FixedSizeIcon name="chevronright" size={12} />}
+ c="text-secondary"
+ ml="1rem"
+ pl="sm"
+ >
+ {location.links.map((link, linkIndex) => (
+ <Box key={linkIndex} className={CS.textWrap} lh="1rem">
+ {link.label}
+ </Box>
+ ))}
+ </Breadcrumbs>
+ )}
+ </Stack>
+ </Menu.Target>
+ <Menu.Dropdown>
+ {link && (
+ <Menu.Item
+ component={ForwardRefLink}
+ to={link.url}
+ leftSection={<FixedSizeIcon name="external" />}
+ >
+ {t`Go to this`}
+ </Menu.Item>
+ )}
+ <Menu.Item
+ component={ForwardRefLink}
+ to={Urls.dependencyGraph({ entry: node })}
+ leftSection={<FixedSizeIcon name="dependencies" />}
+ >
+ {t`View in dependency graph`}
+ </Menu.Item>
+ </Menu.Dropdown>
+ </Menu>
+ );
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorInfo/SidebarErrorInfo.module.css b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorInfo/SidebarErrorInfo.module.css
index 1b2f651934d..7fcc65452a2 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorInfo/SidebarErrorInfo.module.css
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorInfo/SidebarErrorInfo.module.css
@@ -1,4 +1,10 @@
.item {
+ cursor: pointer;
+
+ &:hover {
+ background-color: var(--mb-color-background-secondary);
+ }
+
&:not(:last-child) {
border-bottom: 1px solid var(--mb-color-border);
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorInfo/SidebarErrorInfo.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorInfo/SidebarErrorInfo.tsx
index 633b879cb9d..c1fce875a89 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorInfo/SidebarErrorInfo.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarErrorInfo/SidebarErrorInfo.tsx
@@ -1,42 +1,91 @@
+import { useClipboard } from "@mantine/hooks";
+import cx from "classnames";
+import { t } from "ttag";
+
import { CopyButton } from "metabase/common/components/CopyButton";
-import { Ellipsified } from "metabase/common/components/Ellipsified";
-import { Card, Group, Stack, Title } from "metabase/ui";
-import type { DependencyError, DependencyErrorType } from "metabase-types/api";
+import CS from "metabase/css/core/index.css";
+import {
+ ActionIcon,
+ Badge,
+ Box,
+ Card,
+ FixedSizeIcon,
+ Group,
+ Stack,
+ Title,
+ Tooltip,
+} from "metabase/ui";
+import type { AnalysisFindingErrorType } from "metabase-types/api";
-import { getDependencyErrorTypeCountMessage } from "../../../../utils";
+import type { DependencyError } from "../../../../types";
+import { getErrorTypeLabel } from "../../../../utils";
import S from "./SidebarErrorInfo.module.css";
type SidebarErrorInfoProps = {
- type: DependencyErrorType;
+ type: AnalysisFindingErrorType;
errors: DependencyError[];
};
export function SidebarErrorInfo({ type, errors }: SidebarErrorInfoProps) {
- const title = getDependencyErrorTypeCountMessage(type, errors.length);
+ const count = errors.length;
+ const title = getErrorTypeLabel(type, count);
const details = errors
.map((error) => error.detail)
.filter((detail) => detail != null);
return (
- <Stack gap="sm" role="region" aria-label={title}>
- <Title order={4}>{title}</Title>
+ <Stack role="region" aria-label={getErrorTypeLabel(type)}>
+ <Group gap="sm">
+ <Badge c="text-selected" bg="error">
+ {count}
+ </Badge>
+ <Title order={5}>{title}</Title>
+ </Group>
{details.length > 0 && (
<Card p={0} shadow="none" withBorder>
{details.map((detail, detailIndex) => (
- <Group
- key={detailIndex}
- className={S.item}
- p="md"
- justify="space-between"
- wrap="nowrap"
- >
- <Ellipsified>{detail}</Ellipsified>
- <CopyButton value={detail} />
- </Group>
+ <ErrorItem key={detailIndex} detail={detail} />
))}
</Card>
)}
</Stack>
);
}
+
+type ErrorItemProps = {
+ detail: string;
+};
+
+function ErrorItem({ detail }: ErrorItemProps) {
+ const clipboard = useClipboard();
+
+ const handleClick = () => {
+ clipboard.copy(detail);
+ };
+
+ return (
+ <Tooltip opened={clipboard.copied} label={t`Copied!`}>
+ <Group
+ className={cx(S.item, CS.hoverParent, CS.hoverVisibility)}
+ p="md"
+ justify="space-between"
+ wrap="nowrap"
+ onClick={handleClick}
+ >
+ <Box className={cx(CS.textWrap, CS.textMonospace)} fz="sm" lh="1rem">
+ {detail}
+ </Box>
+ <CopyButton
+ className={CS.hoverChild}
+ value={detail}
+ target={
+ <ActionIcon aria-label={t`Copy`}>
+ <FixedSizeIcon name="copy" />
+ </ActionIcon>
+ }
+ />
+ </Group>
+ </Tooltip>
+ );
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarHeader/SidebarHeader.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarHeader/SidebarHeader.tsx
index 558c47c08cb..92aed4b806e 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarHeader/SidebarHeader.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarHeader/SidebarHeader.tsx
@@ -1,10 +1,15 @@
+import cx from "classnames";
import { t } from "ttag";
import { ForwardRefLink } from "metabase/common/components/Link";
-import { ActionIcon, Anchor, FixedSizeIcon, Group } from "metabase/ui";
+import CS from "metabase/css/core/index.css";
+import * as Urls from "metabase/lib/urls";
+import { ActionIcon, Anchor, FixedSizeIcon, Group, Tooltip } from "metabase/ui";
import type { DependencyNode } from "metabase-types/api";
+import { TOOLTIP_OPEN_DELAY_MS } from "../../../../constants";
import { getNodeLabel, getNodeLink } from "../../../../utils";
+import S from "../ListSidebar.module.css";
type SidebarHeaderProps = {
node: DependencyNode;
@@ -23,18 +28,32 @@ export function SidebarHeader({ node, onClose }: SidebarHeaderProps) {
data-testid="dependency-list-sidebar-header"
>
<Anchor
+ className={cx(CS.textWrap, S.link)}
component={ForwardRefLink}
fz="h3"
fw="bold"
- lh="1.5rem"
+ lh="h3"
to={link?.url ?? ""}
- target="_blank"
>
{getNodeLabel(node)}
</Anchor>
- <ActionIcon aria-label={t`Close`} onClick={onClose}>
- <FixedSizeIcon name="close" />
- </ActionIcon>
+ <Group gap="sm">
+ <Tooltip
+ label={t`View in dependency graph`}
+ openDelay={TOOLTIP_OPEN_DELAY_MS}
+ >
+ <ActionIcon
+ component={ForwardRefLink}
+ to={Urls.dependencyGraph({ entry: node })}
+ aria-label={t`View in dependency graph`}
+ >
+ <FixedSizeIcon name="dependencies" />
+ </ActionIcon>
+ </Tooltip>
+ <ActionIcon aria-label={t`Close`} onClick={onClose}>
+ <FixedSizeIcon name="close" />
+ </ActionIcon>
+ </Group>
</Group>
);
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationInfo/SidebarLocationInfo.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationInfo/SidebarLocationInfo.tsx
index 3249a561b0d..ad44d00c4ce 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationInfo/SidebarLocationInfo.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarLocationInfo/SidebarLocationInfo.tsx
@@ -1,18 +1,19 @@
-import { Fragment } from "react";
+import cx from "classnames";
import { Link } from "react-router";
import { t } from "ttag";
-import { Anchor, Card, Group, Icon, Stack, Title } from "metabase/ui";
+import CS from "metabase/css/core/index.css";
+import { Anchor, Breadcrumbs, FixedSizeIcon, Group } from "metabase/ui";
import type { DependencyNode } from "metabase-types/api";
import { getNodeLocationInfo } from "../../../../utils";
+import S from "../ListSidebar.module.css";
type SidebarLocationInfoProps = {
node: DependencyNode;
};
export function SidebarLocationInfo({ node }: SidebarLocationInfoProps) {
- const title = t`Location`;
const locationInfo = getNodeLocationInfo(node);
if (locationInfo == null) {
@@ -20,21 +21,23 @@ export function SidebarLocationInfo({ node }: SidebarLocationInfoProps) {
}
return (
- <Stack gap="sm" role="region" aria-label={title}>
- <Title order={4}>{title}</Title>
- <Card p="md" shadow="none" withBorder>
+ <div role="region" aria-label={t`Location`}>
+ <Breadcrumbs lh="1rem">
{locationInfo.links.map((link, linkIndex) => (
- <Fragment key={linkIndex}>
- {linkIndex > 0 && <span>/</span>}
- <Anchor component={Link} to={link.url} target="_blank">
- <Group gap="sm" wrap="nowrap">
- {linkIndex === 0 && <Icon name={locationInfo.icon} />}
- {link.label}
- </Group>
- </Anchor>
- </Fragment>
+ <Anchor
+ key={linkIndex}
+ component={Link}
+ className={cx(CS.textWrap, S.link)}
+ lh="1rem"
+ to={link.url}
+ >
+ <Group gap="sm" wrap="nowrap">
+ {linkIndex === 0 && <FixedSizeIcon name={locationInfo.icon} />}
+ {link.label}
+ </Group>
+ </Anchor>
))}
- </Card>
- </Stack>
+ </Breadcrumbs>
+ </div>
);
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarTransformInfo/SidebarTransformInfo.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarTransformInfo/SidebarTransformInfo.tsx
new file mode 100644
index 00000000000..2bbd13c3a81
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarTransformInfo/SidebarTransformInfo.tsx
@@ -0,0 +1,52 @@
+import cx from "classnames";
+import { Link } from "react-router";
+import { t } from "ttag";
+
+import CS from "metabase/css/core/index.css";
+import * as Urls from "metabase/lib/urls";
+import { Anchor, Box, Card, FixedSizeIcon, Group, Stack } from "metabase/ui";
+import type { DependencyNode } from "metabase-types/api";
+
+import { getNodeTransform } from "../../../../utils";
+import S from "../ListSidebar.module.css";
+
+type SidebarTransformInfoProps = {
+ node: DependencyNode;
+};
+
+export function SidebarTransformInfo({ node }: SidebarTransformInfoProps) {
+ const transform = getNodeTransform(node);
+
+ if (transform == null) {
+ return null;
+ }
+
+ return (
+ <Card
+ p={0}
+ shadow="none"
+ withBorder
+ role="region"
+ aria-label={t`Transform`}
+ >
+ <Stack className={S.section} c="text-secondary" p="md" gap="xs">
+ <Box fz="sm" lh="h5">
+ {t`Generated by`}
+ </Box>
+ <Box lh="h4" c="text-primary">
+ <Anchor
+ component={Link}
+ className={cx(CS.textWrap, S.link)}
+ to={Urls.transform(transform.id)}
+ >
+ <Group gap="sm" wrap="nowrap">
+ <FixedSizeIcon name="transform" />
+ {transform.name}
+ </Group>
+ {}
+ </Anchor>
+ </Box>
+ </Stack>
+ </Card>
+ );
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarTransformInfo/index.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarTransformInfo/index.ts
new file mode 100644
index 00000000000..2ff073ea83a
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/SidebarTransformInfo/index.ts
@@ -0,0 +1 @@
+export * from "./SidebarTransformInfo";
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/types.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/types.ts
deleted file mode 100644
index 43920b2e929..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/types.ts
+++ /dev/null
@@ -1,6 +0,0 @@
-import type { DependencyError, DependencyErrorType } from "metabase-types/api";
-
-export type DependencyErrorGroup = {
- type: DependencyErrorType;
- errors: DependencyError[];
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/utils.ts
deleted file mode 100644
index 17d237a8d02..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/ListSidebar/utils.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import type { DependencyError, DependencyErrorType } from "metabase-types/api";
-
-import type { DependencyErrorGroup } from "./types";
-
-export function getDependencyErrorGroups(
- errors: DependencyError[],
-): DependencyErrorGroup[] {
- const groups: Partial<Record<DependencyErrorType, DependencyError[]>> = {};
- for (const error of errors) {
- const group = groups[error.type];
- if (group) {
- group.push(error);
- } else {
- groups[error.type] = [error];
- }
- }
- return Object.values(groups).map((errors) => ({
- type: errors[0].type,
- errors,
- }));
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/utils.ts
index a412b96055a..941dd76c121 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/components/DependencyList/utils.ts
@@ -3,12 +3,9 @@ import type { DependencyGroupType } from "metabase-types/api";
import type { DependencyListMode } from "./types";
const BROKEN_GROUP_TYPES: DependencyGroupType[] = [
+ "table",
"question",
"model",
- "metric",
- "segment",
- "measure",
- "transform",
];
const UNREFERENCED_GROUP_TYPES: DependencyGroupType[] = [
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/routes.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/routes.tsx
index 82bc822dbe8..e6a26fb425e 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/routes.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/routes.tsx
@@ -1,7 +1,5 @@
import { IndexRedirect, IndexRoute, Route } from "react-router";
-import { isCypressActive } from "metabase/env";
-
import { DependencyGraphPage } from "./pages/DependencyGraphPage";
import {
BrokenDependencyListPage,
@@ -13,11 +11,6 @@ export function getDataStudioDependencyRoutes() {
}
export function getDataStudioTasksRoutes() {
- /* TODO (Alex P 01/15/2026): remove isCypressActive once we are ready to release this feature */
- if (!isCypressActive) {
- return null;
- }
-
return (
<>
<IndexRedirect to="broken" />
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/types.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/types.ts
index c5aa3e0f8b7..af29f072b64 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/types.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/types.ts
@@ -1,6 +1,9 @@
import type { ColorName } from "metabase/lib/colors/types";
import type { IconName } from "metabase/ui";
-import type { DependencyGroupType } from "metabase-types/api";
+import type {
+ AnalysisFindingErrorType,
+ DependencyGroupType,
+} from "metabase-types/api";
export type NodeId = string;
@@ -24,6 +27,16 @@ export type DependentGroup = {
count: number;
};
+export type DependencyError = {
+ type: AnalysisFindingErrorType;
+ detail?: string | null;
+};
+
+export type DependencyErrorGroup = {
+ type: AnalysisFindingErrorType;
+ errors: DependencyError[];
+};
+
export type DependencyErrorInfo = {
label: string;
detail?: string | null;
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts
index 228ae7b9c74..f934c066fde 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.ts
@@ -4,20 +4,23 @@ import * as Urls from "metabase/lib/urls";
import type { IconName } from "metabase/ui";
import visualizations from "metabase/visualizations";
import type {
+ AnalysisFindingError,
+ AnalysisFindingErrorType,
CardType,
DependencyEntry,
- DependencyError,
- DependencyErrorType,
DependencyGroupType,
DependencyId,
DependencyNode,
DependencyType,
LastEditInfo,
+ Transform,
UserInfo,
VisualizationDisplay,
} from "metabase-types/api";
import type {
+ DependencyError,
+ DependencyErrorGroup,
DependencyErrorInfo,
DependencyGroupTypeInfo,
DependentGroup,
@@ -414,15 +417,15 @@ export function getNodeViewCount(node: DependencyNode): number | null {
}
}
-export function getNodeDependentsCount(node: DependencyNode): number {
- const dependentsCount = node.dependents_count;
- if (dependentsCount == null) {
- return 0;
+export function getNodeViewCountLabel(viewCount: number): string {
+ return ngettext(msgid`${viewCount} view`, `${viewCount} views`, viewCount);
+}
+
+export function getNodeTransform(node: DependencyNode): Transform | null {
+ if (node.type === "table") {
+ return node.data.transform ?? null;
}
- return Object.values(dependentsCount).reduce(
- (total, count) => total + count,
- 0,
- );
+ return null;
}
export function getCardType(groupType: DependencyGroupType): CardType | null {
@@ -628,24 +631,27 @@ export function getDependentGroupLabel({
}
}
-export function getDependencyErrorTypeLabel(type: DependencyErrorType): string {
+export function getErrorTypeLabel(
+ type: AnalysisFindingErrorType,
+ count = 0,
+): string {
switch (type) {
case "missing-column":
- return t`Missing column`;
+ return count === 1 ? t`Missing column` : t`Missing columns`;
case "missing-table-alias":
- return t`Missing table alias`;
+ return count === 1 ? t`Missing table alias` : t`Missing table aliases`;
case "duplicate-column":
- return t`Duplicate column`;
+ return count === 1 ? t`Duplicate column` : t`Duplicate columns`;
case "syntax-error":
- return t`Syntax error`;
+ return count === 1 ? t`Syntax error` : t`Syntax errors`;
case "validation-error":
- return t`Unknown problem`;
+ return count === 1 ? t`Unknown problem` : t`Unknown problems`;
}
}
-export function getDependencyErrorTypeCountMessage(
- type: DependencyErrorType,
- count: number,
+export function getErrorTypeLabelWithCount(
+ type: AnalysisFindingErrorType,
+ count = 0,
): string {
switch (type) {
case "missing-column":
@@ -681,6 +687,40 @@ export function getDependencyErrorTypeCountMessage(
}
}
+export function getDependentErrorNodesLabel(count = 0): string {
+ return count === 1 ? t`Broken dependent` : t`Broken dependents`;
+}
+
+export function getDependencyErrors(
+ errors: AnalysisFindingError[],
+): DependencyError[] {
+ const errorByKey = new Map<string, DependencyError>();
+ for (const error of errors) {
+ const { error_type: type, error_detail: detail } = error;
+ const key = `${type}-${detail}`;
+ errorByKey.set(key, { type, detail });
+ }
+ return Array.from(errorByKey.values());
+}
+
+export function getDependencyErrorGroups(
+ errors: DependencyError[],
+): DependencyErrorGroup[] {
+ const groups = new Map<AnalysisFindingErrorType, DependencyError[]>();
+ for (const error of errors) {
+ const group = groups.get(error.type);
+ if (group != null) {
+ group.push(error);
+ } else {
+ groups.set(error.type, [error]);
+ }
+ }
+ return Array.from(groups.entries()).map(([type, errors]) => ({
+ type,
+ errors,
+ }));
+}
+
export function getDependencyErrorInfo(
errors: DependencyError[],
): DependencyErrorInfo | undefined {
@@ -690,7 +730,7 @@ export function getDependencyErrorInfo(
if (errors.length === 1) {
const [error] = errors;
- const label = getDependencyErrorTypeLabel(error.type);
+ const label = getErrorTypeLabel(error.type, errors.length);
const detail = error.detail;
return { label, detail };
}
@@ -699,7 +739,7 @@ export function getDependencyErrorInfo(
if (types.size === 1) {
const [type] = types;
return {
- label: getDependencyErrorTypeCountMessage(type, errors.length),
+ label: getErrorTypeLabelWithCount(type, errors.length),
detail: null,
};
}
@@ -714,12 +754,24 @@ export function getDependencyErrorInfo(
};
}
+export function getDependentErrorNodesCount(
+ errors: AnalysisFindingError[],
+): number {
+ const nodeIds = new Set();
+ errors.forEach((error) => {
+ nodeIds.add(
+ getNodeId(error.analyzed_entity_id, error.analyzed_entity_type),
+ );
+ });
+ return nodeIds.size;
+}
+
export function parseString(value: unknown): string | undefined {
return typeof value === "string" ? value : undefined;
}
export function parseNumber(value: unknown): number | undefined {
- if (typeof value === "string") {
+ if (typeof value === "string" && value.trim() !== "") {
const number = Number(value);
return Number.isFinite(number) ? number : undefined;
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.ts b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.ts
index f55da5c4441..b43c4300554 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.ts
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/utils.unit.spec.ts
@@ -1,9 +1,23 @@
import type { IconName } from "metabase/ui";
import registerVisualizations from "metabase/visualizations/register";
-import type { DependencyNode } from "metabase-types/api";
+import type {
+ AnalysisFindingError,
+ AnalysisFindingErrorType,
+ DependencyEntry,
+ DependencyGroupType,
+ DependencyNode,
+ DependencyType,
+} from "metabase-types/api";
import {
+ createMockAnalysisFindingError,
createMockCardDependencyNode,
createMockCardDependencyNodeData,
+ createMockCollection,
+ createMockDashboardDependencyNode,
+ createMockDatabase,
+ createMockDocumentDependencyNode,
+ createMockMeasureDependencyNode,
+ createMockSandboxDependencyNode,
createMockSegmentDependencyNode,
createMockSegmentDependencyNodeData,
createMockSnippetDependencyNode,
@@ -11,10 +25,53 @@ import {
createMockTableDependencyNode,
createMockTableDependencyNodeData,
createMockTransformDependencyNode,
+ createMockUserInfo,
} from "metabase-types/api/mocks";
-import type { DependencyGroupTypeInfo, NodeLink } from "./types";
-import { getNodeIcon, getNodeLink, getNodeTypeInfo } from "./utils";
+import type {
+ DependencyError,
+ DependencyGroupTypeInfo,
+ DependentGroup,
+ NodeLink,
+} from "./types";
+import {
+ getCardType,
+ getCardTypes,
+ getDependencyErrorGroups,
+ getDependencyErrorInfo,
+ getDependencyErrors,
+ getDependencyGroupIcon,
+ getDependencyGroupTitle,
+ getDependencyGroupType,
+ getDependencyGroupTypeInfo,
+ getDependencyType,
+ getDependencyTypes,
+ getDependentErrorNodesCount,
+ getDependentErrorNodesLabel,
+ getDependentGroupLabel,
+ getDependentGroups,
+ getErrorTypeLabel,
+ getErrorTypeLabelWithCount,
+ getNodeCreatedAt,
+ getNodeCreatedBy,
+ getNodeDescription,
+ getNodeIcon,
+ getNodeId,
+ getNodeLabel,
+ getNodeLastEditedAt,
+ getNodeLastEditedBy,
+ getNodeLink,
+ getNodeLocationInfo,
+ getNodeTypeInfo,
+ getNodeViewCount,
+ getSearchQuery,
+ isSameNode,
+ parseBoolean,
+ parseEnum,
+ parseList,
+ parseNumber,
+ parseString,
+} from "./utils";
registerVisualizations();
@@ -209,3 +266,696 @@ describe("getNodeTypeInfo", () => {
},
);
});
+
+describe("isSameNode", () => {
+ it.each<{
+ entry1: DependencyEntry;
+ entry2: DependencyEntry;
+ expected: boolean;
+ }>([
+ {
+ entry1: { id: 1, type: "card" },
+ entry2: { id: 1, type: "card" },
+ expected: true,
+ },
+ {
+ entry1: { id: 1, type: "card" },
+ entry2: { id: 2, type: "card" },
+ expected: false,
+ },
+ {
+ entry1: { id: 1, type: "card" },
+ entry2: { id: 1, type: "table" },
+ expected: false,
+ },
+ ])("should compare nodes correctly", ({ entry1, entry2, expected }) => {
+ expect(isSameNode(entry1, entry2)).toBe(expected);
+ });
+});
+
+describe("getNodeId", () => {
+ it.each<{ id: number; type: DependencyType; expected: string }>([
+ { id: 1, type: "card", expected: "1-card" },
+ { id: 42, type: "table", expected: "42-table" },
+ { id: 100, type: "dashboard", expected: "100-dashboard" },
+ ])("should generate node id for $type", ({ id, type, expected }) => {
+ expect(getNodeId(id, type)).toBe(expected);
+ });
+});
+
+describe("getNodeLabel", () => {
+ it.each<{ node: DependencyNode; expected: string }>([
+ {
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({ name: "My Card" }),
+ }),
+ expected: "My Card",
+ },
+ {
+ node: createMockTableDependencyNode({
+ data: createMockTableDependencyNodeData({ display_name: "My Table" }),
+ }),
+ expected: "My Table",
+ },
+ {
+ node: createMockSandboxDependencyNode({
+ data: {
+ table_id: 1,
+ table: createMockTable({ display_name: "Sandboxed Table" }),
+ },
+ }),
+ expected: "Sandboxed Table",
+ },
+ {
+ node: createMockSandboxDependencyNode({ data: { table_id: 1 } }),
+ expected: "Row and column security rule",
+ },
+ ])("should get label for $node.type", ({ node, expected }) => {
+ expect(getNodeLabel(node)).toBe(expected);
+ });
+});
+
+describe("getNodeDescription", () => {
+ it.each<{ node: DependencyNode; expected: string | null }>([
+ {
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ description: "Card description",
+ }),
+ }),
+ expected: "Card description",
+ },
+ {
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({ description: null }),
+ }),
+ expected: "",
+ },
+ {
+ node: createMockDocumentDependencyNode(),
+ expected: null,
+ },
+ {
+ node: createMockSandboxDependencyNode(),
+ expected: null,
+ },
+ ])("should get description for $node.type", ({ node, expected }) => {
+ expect(getNodeDescription(node)).toBe(expected);
+ });
+});
+
+describe("getNodeLocationInfo", () => {
+ it("should return dashboard location for card in dashboard", () => {
+ const node = createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ dashboard: { id: 1, name: "My Dashboard" },
+ }),
+ });
+ const result = getNodeLocationInfo(node);
+ expect(result?.icon).toBe("dashboard");
+ expect(result?.links[0].label).toBe("My Dashboard");
+ });
+
+ it("should return document location for card in document", () => {
+ const node = createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ dashboard: null,
+ document: { id: 1, name: "My Document" },
+ }),
+ });
+ const result = getNodeLocationInfo(node);
+ expect(result?.icon).toBe("document");
+ expect(result?.links[0].label).toBe("My Document");
+ });
+
+ it("should return collection location for card in collection", () => {
+ const node = createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ dashboard: null,
+ collection: createMockCollection({ name: "My Collection" }),
+ }),
+ });
+ const result = getNodeLocationInfo(node);
+ expect(result?.icon).toBe("collection");
+ expect(result?.links[0].label).toBe("My Collection");
+ });
+
+ it("should return database location for table", () => {
+ const node = createMockTableDependencyNode({
+ data: createMockTableDependencyNodeData({
+ db: createMockDatabase({ id: 1, name: "My Database" }),
+ db_id: 1,
+ schema: "public",
+ }),
+ });
+ const result = getNodeLocationInfo(node);
+ expect(result?.icon).toBe("database");
+ expect(result?.links[0].label).toBe("My Database");
+ expect(result?.links[1].label).toBe("public");
+ });
+
+ it("should return null for sandbox", () => {
+ const node = createMockSandboxDependencyNode();
+ expect(getNodeLocationInfo(node)).toBeNull();
+ });
+
+ it("should return null for transform", () => {
+ const node = createMockTransformDependencyNode();
+ expect(getNodeLocationInfo(node)).toBeNull();
+ });
+});
+
+describe("getNodeCreatedAt", () => {
+ it.each<{ node: DependencyNode; expected: string | null }>([
+ {
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ created_at: "2020-01-01T00:00:00Z",
+ }),
+ }),
+ expected: "2020-01-01T00:00:00Z",
+ },
+ {
+ node: createMockTableDependencyNode(),
+ expected: null,
+ },
+ {
+ node: createMockSandboxDependencyNode(),
+ expected: null,
+ },
+ ])("should get created_at for $node.type", ({ node, expected }) => {
+ expect(getNodeCreatedAt(node)).toBe(expected);
+ });
+});
+
+describe("getNodeCreatedBy", () => {
+ it("should return creator for card", () => {
+ const creator = createMockUserInfo({ common_name: "Test User" });
+ const node = createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({ creator }),
+ });
+ expect(getNodeCreatedBy(node)).toEqual(creator);
+ });
+
+ it("should return null for table", () => {
+ const node = createMockTableDependencyNode();
+ expect(getNodeCreatedBy(node)).toBeNull();
+ });
+});
+
+describe("getNodeLastEditedAt", () => {
+ it("should return last edit timestamp for card", () => {
+ const node = createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ "last-edit-info": {
+ id: 1,
+ email: "[email protected]",
+ first_name: "Test",
+ last_name: "User",
+ timestamp: "2020-06-01T00:00:00Z",
+ },
+ }),
+ });
+ expect(getNodeLastEditedAt(node)).toBe("2020-06-01T00:00:00Z");
+ });
+
+ it("should return null for table", () => {
+ const node = createMockTableDependencyNode();
+ expect(getNodeLastEditedAt(node)).toBeNull();
+ });
+});
+
+describe("getNodeLastEditedBy", () => {
+ it("should return last edit info for card", () => {
+ const lastEditInfo = {
+ id: 1,
+ email: "[email protected]",
+ first_name: "Test",
+ last_name: "User",
+ timestamp: "2020-06-01T00:00:00Z",
+ };
+ const node = createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ "last-edit-info": lastEditInfo,
+ }),
+ });
+ expect(getNodeLastEditedBy(node)).toEqual(lastEditInfo);
+ });
+
+ it("should return null for snippet", () => {
+ const node = createMockSnippetDependencyNode();
+ expect(getNodeLastEditedBy(node)).toBeNull();
+ });
+});
+
+describe("getNodeViewCount", () => {
+ it("should return view count for question", () => {
+ const node = createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ type: "question",
+ view_count: 100,
+ }),
+ });
+ expect(getNodeViewCount(node)).toBe(100);
+ });
+
+ it("should return null for model", () => {
+ const node = createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({
+ type: "model",
+ view_count: 100,
+ }),
+ });
+ expect(getNodeViewCount(node)).toBeNull();
+ });
+
+ it("should return view count for dashboard", () => {
+ const node = createMockDashboardDependencyNode({
+ data: {
+ name: "Dashboard",
+ description: null,
+ created_at: "2020-01-01T00:00:00Z",
+ collection_id: null,
+ moderation_reviews: [],
+ view_count: 50,
+ "last-edit-info": {
+ id: 1,
+ email: "[email protected]",
+ first_name: "Test",
+ last_name: "User",
+ timestamp: "2020-01-01T00:00:00Z",
+ },
+ },
+ });
+ expect(getNodeViewCount(node)).toBe(50);
+ });
+
+ it("should return null for table", () => {
+ const node = createMockTableDependencyNode();
+ expect(getNodeViewCount(node)).toBeNull();
+ });
+});
+
+describe("getCardType", () => {
+ it.each<{ groupType: DependencyGroupType; expected: string | null }>([
+ { groupType: "question", expected: "question" },
+ { groupType: "model", expected: "model" },
+ { groupType: "metric", expected: "metric" },
+ { groupType: "table", expected: null },
+ { groupType: "dashboard", expected: null },
+ ])("should get card type for $groupType", ({ groupType, expected }) => {
+ expect(getCardType(groupType)).toBe(expected);
+ });
+});
+
+describe("getDependencyType", () => {
+ it.each<{ groupType: DependencyGroupType; expected: string }>([
+ { groupType: "question", expected: "card" },
+ { groupType: "model", expected: "card" },
+ { groupType: "metric", expected: "card" },
+ { groupType: "table", expected: "table" },
+ { groupType: "dashboard", expected: "dashboard" },
+ { groupType: "transform", expected: "transform" },
+ ])("should get dependency type for $groupType", ({ groupType, expected }) => {
+ expect(getDependencyType(groupType)).toBe(expected);
+ });
+});
+
+describe("getDependencyGroupType", () => {
+ it.each<{ node: DependencyNode; expected: DependencyGroupType }>([
+ {
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({ type: "question" }),
+ }),
+ expected: "question",
+ },
+ {
+ node: createMockCardDependencyNode({
+ data: createMockCardDependencyNodeData({ type: "model" }),
+ }),
+ expected: "model",
+ },
+ {
+ node: createMockTableDependencyNode(),
+ expected: "table",
+ },
+ {
+ node: createMockDashboardDependencyNode(),
+ expected: "dashboard",
+ },
+ {
+ node: createMockMeasureDependencyNode(),
+ expected: "measure",
+ },
+ ])("should get group type for $node.type", ({ node, expected }) => {
+ expect(getDependencyGroupType(node)).toBe(expected);
+ });
+});
+
+describe("getDependencyGroupTypeInfo", () => {
+ it.each<{
+ groupType: DependencyGroupType;
+ expected: DependencyGroupTypeInfo;
+ }>([
+ {
+ groupType: "question",
+ expected: { label: "Question", color: "text-secondary" },
+ },
+ { groupType: "model", expected: { label: "Model", color: "brand" } },
+ { groupType: "metric", expected: { label: "Metric", color: "summarize" } },
+ { groupType: "table", expected: { label: "Table", color: "brand" } },
+ {
+ groupType: "dashboard",
+ expected: { label: "Dashboard", color: "filter" },
+ },
+ {
+ groupType: "sandbox",
+ expected: { label: "Row and column security rule", color: "error" },
+ },
+ ])("should get type info for $groupType", ({ groupType, expected }) => {
+ expect(getDependencyGroupTypeInfo(groupType)).toEqual(expected);
+ });
+});
+
+describe("getDependencyGroupIcon", () => {
+ it.each<{ groupType: DependencyGroupType; expected: IconName }>([
+ { groupType: "question", expected: "table2" },
+ { groupType: "model", expected: "model" },
+ { groupType: "metric", expected: "metric" },
+ { groupType: "table", expected: "table" },
+ { groupType: "dashboard", expected: "dashboard" },
+ { groupType: "transform", expected: "transform" },
+ ])("should get icon for $groupType", ({ groupType, expected }) => {
+ expect(getDependencyGroupIcon(groupType)).toBe(expected);
+ });
+});
+
+describe("getDependencyTypes", () => {
+ it("should convert group types to dependency types", () => {
+ const groupTypes: DependencyGroupType[] = ["question", "model", "table"];
+ expect(getDependencyTypes(groupTypes)).toEqual(["card", "table"]);
+ });
+
+ it("should deduplicate card types", () => {
+ const groupTypes: DependencyGroupType[] = ["question", "model", "metric"];
+ expect(getDependencyTypes(groupTypes)).toEqual(["card"]);
+ });
+});
+
+describe("getCardTypes", () => {
+ it("should extract card types from group types", () => {
+ const groupTypes: DependencyGroupType[] = ["question", "model", "table"];
+ expect(getCardTypes(groupTypes)).toEqual(["question", "model"]);
+ });
+
+ it("should return empty array for non-card types", () => {
+ const groupTypes: DependencyGroupType[] = ["table", "dashboard"];
+ expect(getCardTypes(groupTypes)).toEqual([]);
+ });
+});
+
+describe("getDependentGroups", () => {
+ it("should return non-zero dependent groups", () => {
+ const node = createMockCardDependencyNode({
+ dependents_count: { question: 5, model: 3, table: 0 },
+ });
+ const result = getDependentGroups(node);
+ expect(result).toEqual([
+ { type: "question", count: 5 },
+ { type: "model", count: 3 },
+ ]);
+ });
+
+ it("should return empty array when no dependents", () => {
+ const node = createMockCardDependencyNode({ dependents_count: {} });
+ expect(getDependentGroups(node)).toEqual([]);
+ });
+});
+
+describe("getDependencyGroupTitle", () => {
+ it('should return "Restricts table data" for sandbox', () => {
+ const node = createMockSandboxDependencyNode();
+ expect(getDependencyGroupTitle(node, [])).toBe("Restricts table data");
+ });
+
+ it('should return "Nothing uses this" when no groups', () => {
+ const node = createMockCardDependencyNode();
+ expect(getDependencyGroupTitle(node, [])).toBe("Nothing uses this");
+ });
+
+ it('should return "Generates" for transform', () => {
+ const node = createMockTransformDependencyNode();
+ const groups: DependentGroup[] = [{ type: "table", count: 1 }];
+ expect(getDependencyGroupTitle(node, groups)).toBe("Generates");
+ });
+
+ it('should return "Used by" for other types with dependents', () => {
+ const node = createMockCardDependencyNode();
+ const groups: DependentGroup[] = [{ type: "question", count: 5 }];
+ expect(getDependencyGroupTitle(node, groups)).toBe("Used by");
+ });
+});
+
+describe("getDependentGroupLabel", () => {
+ it.each<{ type: DependencyGroupType; count: number; expected: string }>([
+ { type: "question", count: 1, expected: "1 question" },
+ { type: "question", count: 5, expected: "5 questions" },
+ { type: "model", count: 1, expected: "1 model" },
+ { type: "model", count: 3, expected: "3 models" },
+ { type: "dashboard", count: 1, expected: "1 dashboard" },
+ { type: "dashboard", count: 2, expected: "2 dashboards" },
+ ])("should format $count $type", ({ type, count, expected }) => {
+ expect(getDependentGroupLabel({ type, count })).toBe(expected);
+ });
+});
+
+describe("getErrorTypeLabel", () => {
+ it.each<{ type: AnalysisFindingErrorType; count: number; expected: string }>([
+ { type: "missing-column", count: 1, expected: "Missing column" },
+ { type: "missing-column", count: 2, expected: "Missing columns" },
+ { type: "syntax-error", count: 1, expected: "Syntax error" },
+ { type: "duplicate-column", count: 3, expected: "Duplicate columns" },
+ ])("should format $type with count $count", ({ type, count, expected }) => {
+ expect(getErrorTypeLabel(type, count)).toBe(expected);
+ });
+});
+
+describe("getErrorTypeLabelWithCount", () => {
+ it.each<{ type: AnalysisFindingErrorType; count: number; expected: string }>([
+ { type: "missing-column", count: 1, expected: "1 missing column" },
+ { type: "missing-column", count: 3, expected: "3 missing columns" },
+ { type: "syntax-error", count: 2, expected: "2 syntax errors" },
+ ])("should format $count $type", ({ type, count, expected }) => {
+ expect(getErrorTypeLabelWithCount(type, count)).toBe(expected);
+ });
+});
+
+describe("getDependencyErrors", () => {
+ it("should deduplicate errors by type and detail", () => {
+ const errors: AnalysisFindingError[] = [
+ createMockAnalysisFindingError({
+ id: 1,
+ error_detail: "column_a",
+ }),
+ createMockAnalysisFindingError({
+ id: 2,
+ error_detail: "column_a",
+ }),
+ createMockAnalysisFindingError({
+ id: 3,
+ error_detail: "column_b",
+ }),
+ ];
+ const result = getDependencyErrors(errors);
+ expect(result).toEqual([
+ { type: "missing-column", detail: "column_a" },
+ { type: "missing-column", detail: "column_b" },
+ ]);
+ });
+});
+
+describe("getDependencyErrorGroups", () => {
+ it("should group errors by type", () => {
+ const errors: DependencyError[] = [
+ { type: "missing-column", detail: "col_a" },
+ { type: "missing-column", detail: "col_b" },
+ { type: "syntax-error", detail: "invalid" },
+ ];
+ const result = getDependencyErrorGroups(errors);
+ expect(result).toEqual([
+ {
+ type: "missing-column",
+ errors: [
+ { type: "missing-column", detail: "col_a" },
+ { type: "missing-column", detail: "col_b" },
+ ],
+ },
+ {
+ type: "syntax-error",
+ errors: [{ type: "syntax-error", detail: "invalid" }],
+ },
+ ]);
+ });
+});
+
+describe("getDependencyErrorInfo", () => {
+ it("should return undefined for empty errors", () => {
+ expect(getDependencyErrorInfo([])).toBeUndefined();
+ });
+
+ it("should return single error info with detail", () => {
+ const errors: DependencyError[] = [
+ { type: "missing-column", detail: "column_name" },
+ ];
+ const result = getDependencyErrorInfo(errors);
+ expect(result).toEqual({
+ label: "Missing column",
+ detail: "column_name",
+ });
+ });
+
+ it("should return count for multiple errors of same type", () => {
+ const errors: DependencyError[] = [
+ { type: "missing-column", detail: "col_a" },
+ { type: "missing-column", detail: "col_b" },
+ ];
+ const result = getDependencyErrorInfo(errors);
+ expect(result).toEqual({
+ label: "2 missing columns",
+ detail: null,
+ });
+ });
+
+ it("should return generic count for multiple error types", () => {
+ const errors: DependencyError[] = [
+ { type: "missing-column", detail: "col_a" },
+ { type: "syntax-error", detail: "invalid" },
+ ];
+ const result = getDependencyErrorInfo(errors);
+ expect(result).toEqual({
+ label: "2 problems",
+ detail: null,
+ });
+ });
+});
+
+describe("getDependentErrorNodesCount", () => {
+ it("should count unique nodes with errors", () => {
+ const errors: AnalysisFindingError[] = [
+ createMockAnalysisFindingError({
+ id: 1,
+ analyzed_entity_id: 1,
+ error_detail: "col_a",
+ }),
+ createMockAnalysisFindingError({
+ id: 2,
+ analyzed_entity_id: 1,
+ error_detail: "col_b",
+ }),
+ createMockAnalysisFindingError({
+ id: 3,
+ analyzed_entity_id: 2,
+ error_detail: "col_a",
+ }),
+ ];
+ expect(getDependentErrorNodesCount(errors)).toBe(2);
+ });
+});
+
+describe("parseString", () => {
+ it.each([
+ { value: "hello", expected: "hello" },
+ { value: "", expected: "" },
+ { value: 123, expected: undefined },
+ { value: null, expected: undefined },
+ { value: undefined, expected: undefined },
+ ])("should parse $value", ({ value, expected }) => {
+ expect(parseString(value)).toBe(expected);
+ });
+});
+
+describe("parseNumber", () => {
+ it.each<{ value: unknown; expected: number | undefined }>([
+ { value: "123", expected: 123 },
+ { value: "3.14", expected: 3.14 },
+ { value: "abc", expected: undefined },
+ { value: "", expected: undefined },
+ { value: " ", expected: undefined },
+ { value: 123, expected: undefined },
+ ])("should parse $value", ({ value, expected }) => {
+ expect(parseNumber(value)).toBe(expected);
+ });
+});
+
+describe("parseBoolean", () => {
+ it.each([
+ { value: "true", expected: true },
+ { value: "false", expected: false },
+ { value: "yes", expected: undefined },
+ { value: true, expected: undefined },
+ { value: null, expected: undefined },
+ ])("should parse $value", ({ value, expected }) => {
+ expect(parseBoolean(value)).toBe(expected);
+ });
+});
+
+describe("parseEnum", () => {
+ const items: readonly string[] = ["a", "b", "c"];
+
+ it.each<{ value: unknown; expected: string | undefined }>([
+ { value: "a", expected: "a" },
+ { value: "b", expected: "b" },
+ { value: "d", expected: undefined },
+ { value: 123, expected: undefined },
+ ])("should parse $value", ({ value, expected }) => {
+ expect(parseEnum(value, items)).toBe(expected);
+ });
+});
+
+describe("parseList", () => {
+ it("should parse array of strings", () => {
+ const result = parseList(["a", "b"], parseString);
+ expect(result).toEqual(["a", "b"]);
+ });
+
+ it("should wrap single value in array", () => {
+ const result = parseList("single", parseString);
+ expect(result).toEqual(["single"]);
+ });
+
+ it("should filter out invalid items", () => {
+ const result = parseList(["a", 123, "b"], parseString);
+ expect(result).toEqual(["a", "b"]);
+ });
+
+ it("should return undefined for null/undefined", () => {
+ expect(parseList(null, parseString)).toBeUndefined();
+ expect(parseList(undefined, parseString)).toBeUndefined();
+ });
+});
+
+describe("getSearchQuery", () => {
+ it.each([
+ { value: "search term", expected: "search term" },
+ { value: " trimmed ", expected: "trimmed" },
+ { value: "", expected: undefined },
+ { value: " ", expected: undefined },
+ ])("should process '$value'", ({ value, expected }) => {
+ expect(getSearchQuery(value)).toBe(expected);
+ });
+});
+
+describe("getDependentErrorNodesLabel", () => {
+ it.each<{ count: number; expected: string }>([
+ { count: 0, expected: "Broken dependents" },
+ { count: 1, expected: "Broken dependent" },
+ { count: 2, expected: "Broken dependents" },
+ { count: 10, expected: "Broken dependents" },
+ ])("should return '$expected' for count $count", ({ count, expected }) => {
+ expect(getDependentErrorNodesLabel(count)).toBe(expected);
+ });
+
+ it("should default to plural form when called without arguments", () => {
+ expect(getDependentErrorNodesLabel()).toBe("Broken dependents");
+ });
+});
diff --git a/frontend/src/metabase-types/api/dependencies.ts b/frontend/src/metabase-types/api/dependencies.ts
index c583d5971c3..76e5d26f81b 100644
--- a/frontend/src/metabase-types/api/dependencies.ts
+++ b/frontend/src/metabase-types/api/dependencies.ts
@@ -55,12 +55,19 @@ type BaseDependencyNode<TType extends DependencyType, TData> = {
type: TType;
data: TData;
dependents_count?: DependentsCount | null;
- dependents_errors?: DependencyError[] | null;
+ dependents_errors?: AnalysisFindingError[] | null;
};
export type TableDependencyNodeData = Pick<
Table,
- "name" | "display_name" | "description" | "db_id" | "schema" | "db" | "fields"
+ | "name"
+ | "display_name"
+ | "description"
+ | "db_id"
+ | "schema"
+ | "db"
+ | "fields"
+ | "transform"
>;
export type TransformDependencyNodeData = Pick<
@@ -199,18 +206,26 @@ export type DependencyNode =
| SegmentDependencyNode
| MeasureDependencyNode;
-export const DEPENDENCY_ERROR_TYPES = [
+export type AnalysisFindingErrorId = number;
+
+export const ANALYSIS_FINDING_ERROR_TYPES = [
"missing-column",
"missing-table-alias",
"duplicate-column",
"syntax-error",
"validation-error",
] as const;
-export type DependencyErrorType = (typeof DEPENDENCY_ERROR_TYPES)[number];
-
-export type DependencyError = {
- type: DependencyErrorType;
- detail?: string | null;
+export type AnalysisFindingErrorType =
+ (typeof ANALYSIS_FINDING_ERROR_TYPES)[number];
+
+export type AnalysisFindingError = {
+ id: AnalysisFindingErrorId;
+ analyzed_entity_id: DependencyId;
+ analyzed_entity_type: DependencyType;
+ source_entity_id?: DependencyId | null;
+ source_entity_type?: DependencyType | null;
+ error_type: AnalysisFindingErrorType;
+ error_detail?: string | null;
};
export type DependencyEdge = {
@@ -233,8 +248,9 @@ export type GetDependencyGraphRequest = {
export type ListNodeDependentsRequest = {
id: DependencyId;
type: DependencyType;
- dependent_type: DependencyType;
- dependent_card_type?: CardType;
+ dependent_types?: DependencyType[];
+ dependent_card_types?: CardType[];
+ broken?: boolean;
archived?: boolean;
};
@@ -256,7 +272,8 @@ export type CheckTransformDependenciesRequest = Pick<Transform, "id"> &
export const DEPENDENCY_SORT_COLUMNS = [
"name",
"location",
- "dependents-count",
+ "dependents-errors",
+ "dependents-with-errors",
] as const;
export type DependencySortColumn = (typeof DEPENDENCY_SORT_COLUMNS)[number];
@@ -269,6 +286,13 @@ export type DependencySortingOptions = {
direction: DependencySortDirection;
};
+/**
+ * Entity types that can be the source of validation errors (breaking other entities).
+ * Only tables and cards can be sources of errors in analysis_finding_error.
+ */
+export const BREAKING_ENTITY_TYPES = ["card", "table"] as const;
+export type BreakingEntityType = (typeof BREAKING_ENTITY_TYPES)[number];
+
export type ListBrokenGraphNodesRequest = PaginationRequest & {
types?: DependencyType[];
card_types?: CardType[];
diff --git a/frontend/src/metabase-types/api/mocks/dependencies.ts b/frontend/src/metabase-types/api/mocks/dependencies.ts
index a07776ea09c..70d34a04a6b 100644
--- a/frontend/src/metabase-types/api/mocks/dependencies.ts
+++ b/frontend/src/metabase-types/api/mocks/dependencies.ts
@@ -1,13 +1,22 @@
import type {
+ AnalysisFindingError,
CardDependencyNode,
CardDependencyNodeData,
CheckCardDependenciesRequest,
CheckDependenciesResponse,
CheckSnippetDependenciesRequest,
CheckTransformDependenciesRequest,
+ DashboardDependencyNode,
+ DashboardDependencyNodeData,
DependencyEdge,
DependencyEntry,
DependencyGraph,
+ DocumentDependencyNode,
+ DocumentDependencyNodeData,
+ MeasureDependencyNode,
+ MeasureDependencyNodeData,
+ SandboxDependencyNode,
+ SandboxDependencyNodeData,
SegmentDependencyNode,
SegmentDependencyNodeData,
SnippetDependencyNode,
@@ -28,6 +37,18 @@ export function createMockDependencyEntry(
};
}
+export function createMockAnalysisFindingError(
+ opts?: Partial<AnalysisFindingError>,
+): AnalysisFindingError {
+ return {
+ id: 1,
+ analyzed_entity_id: 1,
+ analyzed_entity_type: "card",
+ error_type: "missing-column",
+ ...opts,
+ };
+}
+
export function createMockTableDependencyNodeData(
opts?: Partial<TableDependencyNodeData>,
): TableDependencyNodeData {
@@ -213,3 +234,97 @@ export function createMockCheckDependenciesResponse(
...opts,
};
}
+
+export function createMockDashboardDependencyNodeData(
+ opts?: Partial<DashboardDependencyNodeData>,
+): DashboardDependencyNodeData {
+ return {
+ name: "Dashboard",
+ description: null,
+ created_at: "2020-01-01T00:00:00Z",
+ collection_id: null,
+ moderation_reviews: [],
+ ...opts,
+ } as DashboardDependencyNodeData;
+}
+
+export function createMockDashboardDependencyNode(
+ opts?: Partial<DashboardDependencyNode>,
+): DashboardDependencyNode {
+ return {
+ id: 1,
+ type: "dashboard",
+ data: createMockDashboardDependencyNodeData(),
+ dependents_count: {},
+ ...opts,
+ };
+}
+
+export function createMockDocumentDependencyNodeData(
+ opts?: Partial<DocumentDependencyNodeData>,
+): DocumentDependencyNodeData {
+ return {
+ name: "Document",
+ created_at: "2020-01-01T00:00:00Z",
+ collection_id: null,
+ ...opts,
+ } as DocumentDependencyNodeData;
+}
+
+export function createMockDocumentDependencyNode(
+ opts?: Partial<DocumentDependencyNode>,
+): DocumentDependencyNode {
+ return {
+ id: 1,
+ type: "document",
+ data: createMockDocumentDependencyNodeData(),
+ dependents_count: {},
+ ...opts,
+ };
+}
+
+export function createMockSandboxDependencyNodeData(
+ opts?: Partial<SandboxDependencyNodeData>,
+): SandboxDependencyNodeData {
+ return {
+ table_id: 1,
+ ...opts,
+ };
+}
+
+export function createMockSandboxDependencyNode(
+ opts?: Partial<SandboxDependencyNode>,
+): SandboxDependencyNode {
+ return {
+ id: 1,
+ type: "sandbox",
+ data: createMockSandboxDependencyNodeData(),
+ dependents_count: {},
+ ...opts,
+ };
+}
+
+export function createMockMeasureDependencyNodeData(
+ opts?: Partial<MeasureDependencyNodeData>,
+): MeasureDependencyNodeData {
+ return {
+ name: "Measure",
+ description: null,
+ table_id: 1,
+ created_at: "2020-01-01T00:00:00Z",
+ creator_id: 1,
+ ...opts,
+ };
+}
+
+export function createMockMeasureDependencyNode(
+ opts?: Partial<MeasureDependencyNode>,
+): MeasureDependencyNode {
+ return {
+ id: 1,
+ type: "measure",
+ data: createMockMeasureDependencyNodeData(),
+ dependents_count: {},
+ ...opts,
+ };
+}
diff --git a/frontend/src/metabase/ui/components/icons/Icon/icons/broken_link.svg b/frontend/src/metabase/ui/components/icons/Icon/icons/broken_link.svg
new file mode 100644
index 00000000000..e9f1b97edff
--- /dev/null
+++ b/frontend/src/metabase/ui/components/icons/Icon/icons/broken_link.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentcolor" viewBox="0 0 16 16"><path d="M10.394 11.418a.77.77 0 0 1 .77.769v1.794a.77.77 0 0 1-1.539 0v-1.794c0-.425.344-.769.769-.769M3.37 7.307a.77.77 0 0 1 1.09 1.088L3.444 9.406a2.227 2.227 0 0 0 .054 3.143l.162.14a2.226 2.226 0 0 0 2.927-.14L7.6 11.535a.77.77 0 0 1 1.088 1.088l-1.033 1.032a3.766 3.766 0 0 1-5.225 0h-.001a3.76 3.76 0 0 1-.09-5.316l.009-.01zm10.612 2.317a.768.768 0 1 1 0 1.537h-1.795a.768.768 0 1 1 0-1.537zM10.96 1.29a3.76 3.76 0 0 1 2.612 1.055h.001a3.76 3.76 0 0 1 .18 5.217 1 1 0 0 1-.089.11l-1.028 1.023a.769.769 0 0 1-1.084-1.09l.949-.947a1 1 0 0 1 .056-.065 2.225 2.225 0 0 0-.052-3.14l-.162-.143a2.23 2.23 0 0 0-2.928.142l-1.02 1.014a.77.77 0 0 1-1.084-1.09l1.028-1.023.008-.008.134-.123a3.76 3.76 0 0 1 2.479-.932M3.813 4.839a.77.77 0 1 1 0 1.538H2.018a.77.77 0 0 1 0-1.538h1.793zM5.607 1.25c.425 0 .769.344.769.769v1.794a.769.769 0 0 1-1.538 0V2.02a.77.77 0 0 1 .77-.769z"/></svg>
diff --git a/frontend/src/metabase/ui/components/icons/Icon/icons/index.ts b/frontend/src/metabase/ui/components/icons/Icon/icons/index.ts
index 89b33440fe6..c6696ec68a3 100644
--- a/frontend/src/metabase/ui/components/icons/Icon/icons/index.ts
+++ b/frontend/src/metabase/ui/components/icons/Icon/icons/index.ts
@@ -70,6 +70,8 @@ import bookmark_filled_component from "./bookmark_filled.svg?component";
import bookmark_filled_source from "./bookmark_filled.svg?source";
import breakout_component from "./breakout.svg?component";
import breakout_source from "./breakout.svg?source";
+import broken_link_component from "./broken_link.svg?component";
+import broken_link_source from "./broken_link.svg?source";
import bubble_component from "./bubble.svg?component";
import bubble_source from "./bubble.svg?source";
import bug_component from "./bug.svg?component";
@@ -510,6 +512,8 @@ import unpin_component from "./unpin.svg?component";
import unpin_source from "./unpin.svg?source";
import unpublish_component from "./unpublish.svg?component";
import unpublish_source from "./unpublish.svg?source";
+import unreferenced_component from "./unreferenced.svg?component";
+import unreferenced_source from "./unreferenced.svg?source";
import unsubscribe_component from "./unsubscribe.svg?component";
import unsubscribe_source from "./unsubscribe.svg?source";
import upload_component from "./upload.svg?component";
@@ -679,6 +683,10 @@ export const Icons: Record<IconName, { component: React.VFC; source: string }> =
component: breakout_component,
source: breakout_source,
},
+ broken_link: {
+ component: broken_link_component,
+ source: broken_link_source,
+ },
bubble: {
component: bubble_component,
source: bubble_source,
@@ -1537,6 +1545,10 @@ export const Icons: Record<IconName, { component: React.VFC; source: string }> =
component: unpublish_component,
source: unpublish_source,
},
+ unreferenced: {
+ component: unreferenced_component,
+ source: unreferenced_source,
+ },
unsubscribe: {
component: unsubscribe_component,
source: unsubscribe_source,
@@ -1676,6 +1688,7 @@ export type IconName =
| "bolt_filled"
| "breakout"
| "bubble"
+ | "broken_link"
| "burger"
| "calendar"
| "camera"
@@ -1891,6 +1904,7 @@ export type IconName =
| "unknown"
| "unpin"
| "unpublish"
+ | "unreferenced"
| "unsubscribe"
| "upload"
| "variable"
diff --git a/frontend/src/metabase/ui/components/icons/Icon/icons/unreferenced.svg b/frontend/src/metabase/ui/components/icons/Icon/icons/unreferenced.svg
new file mode 100644
index 00000000000..c9399e500bd
--- /dev/null
+++ b/frontend/src/metabase/ui/components/icons/Icon/icons/unreferenced.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentcolor" viewBox="0 0 16 16"><path d="M8.99 13.117a.77.77 0 1 1 .292 1.51 6.8 6.8 0 0 1-2.565 0 .77.77 0 0 1 .293-1.51 5.2 5.2 0 0 0 1.98 0m3.325-2.194a.77.77 0 0 1 1.274.863 6.8 6.8 0 0 1-1.824 1.816.768.768 0 0 1-.857-1.278 5.2 5.2 0 0 0 1.407-1.401m-9.708-.225a.77.77 0 0 1 1.067.21c.372.555.85 1.032 1.402 1.406a.77.77 0 0 1-.863 1.274 6.8 6.8 0 0 1-1.815-1.823.77.77 0 0 1 .21-1.067zM1.373 6.717a.77.77 0 0 1 1.51.293 5.2 5.2 0 0 0 0 1.98.77.77 0 0 1-1.51.292 6.8 6.8 0 0 1 0-2.565m12.353-.609a.77.77 0 0 1 .9.609 6.8 6.8 0 0 1 0 2.565.77.77 0 0 1-1.509-.292 5.2 5.2 0 0 0 0-1.98.77.77 0 0 1 .608-.902zm-3.008-3.492a.77.77 0 0 1 1.068-.205 6.8 6.8 0 0 1 1.816 1.822.77.77 0 0 1-1.278.859 5.2 5.2 0 0 0-1.401-1.408.77.77 0 0 1-.205-1.068m-6.485-.218a.77.77 0 0 1 .859 1.276 5.2 5.2 0 0 0-1.408 1.402.77.77 0 0 1-1.273-.862 6.8 6.8 0 0 1 1.822-1.816m2.484-1.025a6.8 6.8 0 0 1 2.565 0 .77.77 0 1 1-.292 1.51 5.2 5.2 0 0 0-1.98 0 .77.77 0 0 1-.293-1.51"/></svg>
diff --git a/src/metabase/lib/schema/validate.cljc b/src/metabase/lib/schema/validate.cljc
index 06e3c0e6d95..5fa910e5e3c 100644
--- a/src/metabase/lib/schema/validate.cljc
+++ b/src/metabase/lib/schema/validate.cljc
@@ -5,42 +5,40 @@
(mr/def ::missing-column-error
[:map
- [:type [:= :validate/missing-column]]
+ [:type [:= :missing-column]]
[:name :string]])
(mr/def ::missing-table-alias-error
[:map
- [:type [:= :validate/missing-table-alias]]
+ [:type [:= :missing-table-alias]]
[:name :string]])
(mr/def ::duplicate-column-error
[:map
- [:type [:= :validate/duplicate-column]]
+ [:type [:= :duplicate-column]]
[:name :string]])
(mr/def ::syntax-error
[:map
- [:type [:= :validate/syntax-error]]])
+ [:type [:= :syntax-error]]])
(mr/def ::validation-exception-error
[:map
- [:type [:= :validate/validation-exception-error]]
+ [:type [:= :validation-exception-error]]
[:message :string]])
(mr/def ::validate-error-type
- [:and
- :keyword
- [:fn {:error/message "Must be in the validate ns"} #(= (namespace %) "validate")]])
+ [:enum :missing-column :missing-table-alias :duplicate-column :syntax-error :validation-exception-error])
(mr/def ::error
[:and
[:map [:type {:decode/normalize common/normalize-keyword} ::validate-error-type]]
[:multi {:dispatch #(-> % :type keyword)}
- [:validate/missing-column [:ref ::missing-column-error]]
- [:validate/missing-table-alias [:ref ::missing-table-alias-error]]
- [:validate/duplicate-column [:ref ::duplicate-column-error]]
- [:validate/syntax-error [:ref ::syntax-error]]
- [:validate/validation-exception-error [:ref ::validation-exception-error]]]])
+ [:missing-column [:ref ::missing-column-error]]
+ [:missing-table-alias [:ref ::missing-table-alias-error]]
+ [:duplicate-column [:ref ::duplicate-column-error]]
+ [:syntax-error [:ref ::syntax-error]]
+ [:validation-exception-error [:ref ::validation-exception-error]]]])
(mr/def ::source-entity-type
"The type of the source entity causing an error."
@@ -61,8 +59,8 @@
[:source-entity-type {:optional true} [:maybe ::source-entity-type]]
[:source-entity-id {:optional true} [:maybe pos-int?]]]
[:multi {:dispatch #(-> % :type keyword)}
- [:validate/missing-column [:merge [:ref ::missing-column-error] [:ref ::source-entity]]]
- [:validate/missing-table-alias [:merge [:ref ::missing-table-alias-error] [:ref ::source-entity]]]
- [:validate/duplicate-column [:merge [:ref ::duplicate-column-error] [:ref ::source-entity]]]
- [:validate/syntax-error [:merge [:ref ::syntax-error] [:ref ::source-entity]]]
- [:validate/validation-exception-error [:merge [:ref ::validation-exception-error] [:ref ::source-entity]]]]])
+ [:missing-column [:merge [:ref ::missing-column-error] [:ref ::source-entity]]]
+ [:missing-table-alias [:merge [:ref ::missing-table-alias-error] [:ref ::source-entity]]]
+ [:duplicate-column [:merge [:ref ::duplicate-column-error] [:ref ::source-entity]]]
+ [:syntax-error [:merge [:ref ::syntax-error] [:ref ::source-entity]]]
+ [:validation-exception-error [:merge [:ref ::validation-exception-error] [:ref ::source-entity]]]]])
diff --git a/src/metabase/lib/validate.cljc b/src/metabase/lib/validate.cljc
index c05b1b16802..441509721d0 100644
--- a/src/metabase/lib/validate.cljc
+++ b/src/metabase/lib/validate.cljc
@@ -14,30 +14,30 @@
(mu/defn missing-column-error :- [:ref ::lib.schema.validate/missing-column-error]
"Create a missing-column lib validation error"
[col-name :- :string]
- {:type :validate/missing-column
+ {:type :missing-column
:name col-name})
(mu/defn missing-table-alias-error :- [:ref ::lib.schema.validate/missing-table-alias-error]
"Create a missing-table-alias lib validation error"
[alias-name :- :string]
- {:type :validate/missing-table-alias
+ {:type :missing-table-alias
:name alias-name})
(mu/defn duplicate-column-error :- [:ref ::lib.schema.validate/duplicate-column-error]
"Create a duplicate-column lib validation error"
[col-name :- :string]
- {:type :validate/duplicate-column
+ {:type :duplicate-column
:name col-name})
(mu/defn syntax-error :- [:ref ::lib.schema.validate/syntax-error]
"Create a syntax-error lib validation error"
[]
- {:type :validate/syntax-error})
+ {:type :syntax-error})
(mu/defn validation-exception-error :- [:ref ::lib.schema.validate/validation-exception-error]
"Create a validation-exception-error lib validation error"
[message :- :string]
- {:type :validate/validation-exception-error
+ {:type :validation-exception-error
:message message})
(defn- extract-source-from-field-ref
@@ -113,7 +113,7 @@
(mu/defn find-bad-refs-with-source :- [:set ::lib.schema.validate/error-with-source]
"Like [[find-bad-refs]] but includes source entity information for each error.
Returns a set of error maps, each containing:
- - `:type` - the error type (e.g., `:validate/missing-column`)
+ - `:type` - the error type (e.g., `:missing-column`)
- `:name` - the column name (for missing-column errors)
- `:source-entity-type` - optional, `:table` or `:card` if source could be determined
- `:source-entity-id` - optional, the ID of the source entity"
diff --git a/test/metabase/lib/validate_test.cljc b/test/metabase/lib/validate_test.cljc
index 7659b047b62..d35c2a4965a 100644
--- a/test/metabase/lib/validate_test.cljc
+++ b/test/metabase/lib/validate_test.cljc
@@ -15,7 +15,7 @@
bad-query (assoc-in query [:stages 0 :filters 0 2 2] "missingcol")
errors (lib/find-bad-refs-with-source bad-query)]
(is (= 1 (count errors)))
- (is (= {:type :validate/missing-column
+ (is (= {:type :missing-column
:source-entity-type :table
:source-entity-id (meta/id :orders)
:name "missingcol"}
@@ -34,7 +34,7 @@
bad-query (assoc-in query [:stages 0 :filters 0 2 2] "missingcol")
errors (lib/find-bad-refs-with-source bad-query)]
(is (= 1 (count errors)))
- (is (= {:type :validate/missing-column
+ (is (= {:type :missing-column
:source-entity-type :card
:source-entity-id 101
:name "missingcol"}
@@ -59,7 +59,7 @@
bad-query (assoc-in filter-query [:stages 0 :filters 0 2 2] "missingcol")
errors (lib/find-bad-refs-with-source bad-query)]
(is (= 1 (count errors)))
- (is (= {:type :validate/missing-column
+ (is (= {:type :missing-column
:source-entity-type :table
:source-entity-id (meta/id :products)
:name "missingcol"}
@@ -87,7 +87,7 @@
bad-query (assoc-in filter-query [:stages 0 :filters 0 2 2] "missingcol")
errors (lib/find-bad-refs-with-source bad-query)]
(is (= 1 (count errors)))
- (is (= {:type :validate/missing-column
+ (is (= {:type :missing-column
:source-entity-type :card
:source-entity-id 101
:name "missingcol"}
@@ -135,11 +135,11 @@
(assoc-in [:stages 0 :filters 1 2 2] "missingcol2"))
errors (lib/find-bad-refs-with-source bad-query)]
(is (= 2 (count errors)))
- (is (= #{{:type :validate/missing-column
+ (is (= #{{:type :missing-column
:source-entity-type :table
:source-entity-id (meta/id :products)
:name "missingcol1"}
- {:type :validate/missing-column
+ {:type :missing-column
:source-entity-type :card
:source-entity-id 101
:name "missingcol2"}}
@@ -158,7 +158,7 @@
bad-query (assoc-in filter-query [:stages 1 :filters 0 2 2] "missingcol")
errors (lib/find-bad-refs-with-source bad-query)]
(is (= 1 (count errors)))
- (is (= {:type :validate/missing-column
+ (is (= {:type :missing-column
:name "missingcol"}
(first errors))))))
@@ -172,7 +172,7 @@
bad-query (assoc-in filter-query [:stages 0 :filters 0 2 2] "missingcol")
errors (lib/find-bad-refs-with-source bad-query)]
(is (= 1 (count errors)))
- (is (= {:type :validate/missing-column
+ (is (= {:type :missing-column
:source-entity-type :table
:source-entity-id (meta/id :orders)
:name "missingcol"}