Skip to content

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

Fix schema breadcrumb after table route refresh (#75428)

Andersonce69cec459bc
diff --git a/frontend/src/metabase/query_builder/actions/core/initializeQB.ts b/frontend/src/metabase/query_builder/actions/core/initializeQB.ts
index 07766bebad5..57826570662 100644
--- a/frontend/src/metabase/query_builder/actions/core/initializeQB.ts
+++ b/frontend/src/metabase/query_builder/actions/core/initializeQB.ts
@@ -15,7 +15,11 @@ import {
import { loadMetadataForCard } from "metabase/questions/actions";
import { setErrorPage } from "metabase/redux/app";
import type { DispatchFn } from "metabase/redux/hooks";
-import { fetchTableMetadata, updateMetadata } from "metabase/redux/metadata";
+import {
+ fetchDatabaseMetadata,
+ fetchTableMetadata,
+ updateMetadata,
+} from "metabase/redux/metadata";
import { INITIALIZE_QB, resetQB } from "metabase/redux/query-builder";
import type {
Dispatch,
@@ -319,6 +323,10 @@ async function handleQBInit(
dispatch(setErrorPage(NOT_FOUND_ERROR));
return;
}
+ await dispatch(fetchDatabaseMetadata(table.db_id));
+ if (isStale()) {
+ return;
+ }
// The /table URL only carries the table id; resolve its db so the QB can
// build the table's default ad-hoc question, just like `?db=&table=`.
options = {
diff --git a/frontend/src/metabase/query_builder/actions/core/initializeQB.unit.spec.ts b/frontend/src/metabase/query_builder/actions/core/initializeQB.unit.spec.ts
index 4542cca380e..7956eb9658c 100644
--- a/frontend/src/metabase/query_builder/actions/core/initializeQB.unit.spec.ts
+++ b/frontend/src/metabase/query_builder/actions/core/initializeQB.unit.spec.ts
@@ -7,6 +7,7 @@ import * as rtkEndpointUtils from "metabase/api/utils/run-rtk-endpoint";
import * as CardLib from "metabase/common/utils/card";
import * as questionActions from "metabase/questions/actions";
import { setErrorPage } from "metabase/redux/app";
+import * as metadataActions from "metabase/redux/metadata";
import * as sharedQB from "metabase/redux/query-builder";
import { createMockState } from "metabase/redux/store/mocks";
import { getMetadata } from "metabase/selectors/metadata";
@@ -1001,6 +1002,17 @@ describe("QB Actions > initializeQB", () => {
expect(result.card.displayIsLocked).toBeFalsy();
});
+ it("fetches database metadata for schema breadcrumbs (metabase#75393)", async () => {
+ const fetchDatabaseMetadataSpy = jest.spyOn(
+ metadataActions,
+ "fetchDatabaseMetadata",
+ );
+
+ await setupTableRoute(ORDERS_ID);
+
+ expect(fetchDatabaseMetadataSpy).toHaveBeenCalledWith(SAMPLE_DB_ID);
+ });
+
it("shows a not-found error for an unknown table", async () => {
const { dispatch } = await setupTableRoute(999999);
expect(dispatch).toHaveBeenCalledWith(