metabase / metabase

The simplest, fastest way to get business intelligence and analytics to everyone in your company :yum:
https://metabase.com
Other
38.04k stars 5.05k forks source link

Display issues affecting native models referencing columns with mapped values #43390

Open zbodi74 opened 3 months ago

zbodi74 commented 3 months ago

Describe the bug

Display issues and model corruption might occur when a native model references columns with custom mapped display values set in Table Metadata. These include:

To Reproduce

  1. In Admin Settings / Table Metadata / Sample Database / Reviews, set up a custom mapping for the Rating column.

  2. Create a native model which uses this table: select distinct rating from reviews, in the model metadata set 'Database column this maps to' to the correct source column. Save the model.

  3. The mapped values are displayed correctly.

    image
  4. Click on '...' / Edit query definition, the preview shows the mapped values

    image
  5. Refresh the preview (Cmd+Enter or click the refresh icon in the editor)

7(!) The non-mapped values are shown

image
  1. Now click on cancel to stop editing the model 9(!) The column is displayed twice with mapped and unmapped values:

    image
  2. Reloading the page resolves this.

  3. Still using the same model, go to '...' / Edit Metadata, update the description and Save Changes.

12(!) The model breaks:

image

Expected behavior

Each of the steps should work

Logs

No response

Information about your Metabase installation

Seen on 1.49.8 and 1.49.13

Severity

Reported by a customer

Additional context

No response

bshepherdson commented 3 months ago

This seems like it's coming from confusion in MLv2 and/or the FE between querying/previewing "inside" the model and "outside" the model.

"Inside" the model, which is to say querying against the model's definition directly, the model's metadata overrides should not be applied. It should return the "rating" column exactly as it comes from SQL, as a simple number.

"Outside" the model, the metadata overrides should be visible. That means the rating native column is linked to the Reviews.RATING Field, which has a custom mapping in the Table Metadata.