8000 Don't offer drill-throughs when top-level column doesn't exist by galdre · Pull Request #66907 · metabase/metabase · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@galdre
Copy link
Contributor
@galdre galdre commented Dec 12, 2025

Closes #66715

Description

The issue is well-documented. The summary: we are offering drill-throughs on custom columns defined after aggregation, but those custom columns don't exist in the base query.

I see three options:

  1. Offer the drill-throughs, but then explain the error well to the user (this way they're not left wondering why the drill-through isn't present).
  2. Offer the drill-throughs, but it only takes you to the original data source, showing all rows (not a very helpful drill-through).
  3. Don't offer the drill-through.

Option 3 was suggested by @alexyarosh on #66715, and it's the one I went with here. The error presented in such a way that lib.underlying/top-level-column for a dimension was returning nil, and we were happily putting that nil into the query we constructed.

I created a utility to filter dimensions by whether or not the top-level-column can be resolved, and used this for the underlying-records drill-through (from the original issue) as well as the pivot drill-through (which behaved similarly). If no dimensions have a top-level column, the drill-through is not available. If some do, we offer the partial drill-through.

How to verify

Copied from the issue:

For an artisanal handcrafted version:

  1. Create a GUI question "Count of products by category" on the sample DB
  2. After the aggregation, add a custom column, it can even be just returning [Category]
Image
  1. Visualize as a bar chart with the custom column on the X axis
Image
  1. Use the "See these records" drillthrough on the chart

Demo

Loom

Checklist

  • Tests have been added/updated to cover changes in this PR

@galdre galdre added the backport Automatically create PR on current release branch on merge label Dec 12, 2025
@galdre galdre changed the title Galdre/issue/66715 Don't offer impossible drill-throughs Dec 12, 2025
@galdre galdre changed the title Don't offer impossible drill-throughs Don't offer drill-throughs when top-level column doesn't exist Dec 12, 2025
@galdre galdre requested a review from a team December 12, 2025 21:58
Copy link
Contributor
@metamben metamben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

@github-actions
Copy link
Contributor
github-actions bot commented Dec 15, 2025

e2e tests failed on f36ca453cca05da236b93ea055facefd7f70e550-1

e2e test run

File Test Name
dashboardsAndQuestions.cy.spec.ts Cache invalidation for dashboards and questions > ee > adaptive and duration strategies > questions can use duration strategy
embed-flow-enable-embed-js.cy.spec.ts scenarios > embedding > sdk iframe embed setup > enable embed js > ee > shows the Enable to Continue button and enables embedding on click
embed-options.cy.spec.ts scenarios > embedding > sdk iframe embed options passthrough > shows a static question with drills=false

@galdre galdre added double-backport and removed backport Automatically create PR on current release branch on merge labels Dec 15, 2025
@galdre galdre merged commit 1aaee4e into master Dec 15, 2025
412 of 423 checks passed
@galdre galdre deleted the galdre/issue/66715 branch December 15, 2025 23:24
Comment on lines 144 to +145
pivots (into {} (for [pivot-type breakout-pivot-types
:let [pred (get pivot-type-predicates pivot-type)
columns (pivot-drill-pred query stage-number context pred)]
:when (not-empty columns)]
:let [pred (get pivot-type-predicates pivot-type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The :let and :when keywords in the for comprehension should be aligned consistently. According to the Metabase Clojure style, when using for bindings, the binding clauses should be vertically aligned.

Consider:

Suggested change
pivots (into {} (for [pivot-type breakout-pivot-types
:let [pred (get pivot-type-predicates pivot-type)
columns (pivot-drill-pred query stage-number context pred)]
:when (not-empty columns)]
:let [pred (get pivot-type-predicates pivot-type)
pivots (into {} (for [pivot-type breakout-pivot-types
:let [pred (get pivot-type-predicates pivot-type)
columns (pivot-drill-pred query stage-number context pred)]
:when (not-empty columns)]

The extra spaces after :let and :when are inconsistent with standard formatting where keywords should have consistent spacing.

github-automation-metabase pushed a commit that referenced this pull request Dec 15, 2025
The summary: we are offering drill-throughs on custom columns defined after aggregation, but those custom columns don't exist in the base query. The error presented in such a way that `lib.underlying/top-level-column` for a dimension was returning `nil`, and we were happily putting that `nil` into the query we constructed.

I created a utility to filter dimensions by whether or not the top-level-column can be resolved, and used this for the underlying-records drill-through (from the original issue) as well as the pivot drill-through (which behaved similarly). If no dimensions have a top-level column, the drill-through is not available. If some do, we offer the partial drill-through.
@metabase-bot
Copy link
Contributor
metabase-bot bot commented Dec 15, 2025

Code Review Summary

I've reviewed the Clojure code changes in this PR. The implementation looks solid and addresses issue #66715 correctly by filtering out dimensions that can't be traced back to the top-level query.

Style Issues Found:

  1. src/metabase/lib/drill_thru/pivot.cljc - Minor formatting inconsistency with :let and :when keyword alignment in the for comprehension (see inline comment)

Implementation Notes:

✅ The new traceable-dimensions function is well-designed and properly documented
✅ Test coverage is comprehensive with new tests for the regression case
✅ The logic correctly prevents invalid drill-throughs on post-aggregation expressions
✅ Code comments clearly explain the reasoning behind the filtering

The solution appropriately addresses the root cause by preventing drill-throughs when dimensions reference columns that don't exist in the top-level query, rather than allowing them and showing an error.

github-automation-metabase pushed a commit that referenced this pull request Dec 15, 2025
The summary: we are offering drill-throughs on custom columns defined after aggregation, but those custom columns don't exist in the base query. The error presented in such a way that `lib.underlying/top-level-column` for a dimension was returning `nil`, and we were happily putting that `nil` into the query we constructed.

I created a utility to filter dimensions by whether or not the top-level-column can be resolved, and used this for the underlying-records drill-through (from the original issue) as well as the pivot drill-through (which behaved similarly). If no dimensions have a top-level column, the drill-through is not available. If some do, we offer the partial drill-through.
github-automation-metabase added a commit that referenced this pull request Dec 16, 2025
… (#66986)

The summary: we are offering drill-throughs on custom columns defined after aggregation, but those custom columns don't exist in the base query. The error presented in such a way that `lib.underlying/top-level-column` for a dimension was returning `nil`, and we were happily putting that `nil` into the query we constructed.

I created a utility to filter dimensions by whether or not the top-level-column can be resolved, and used this for the underlying-records drill-through (from the original issue) as well as the pivot drill-through (which behaved similarly). If no dimensions have a top-level column, the drill-through is not available. If some do, we offer the partial drill-through.

Co-authored-by: Timothy S. Dean <timothy.dean@metabase.com>
github-automation-metabase added a commit that referenced this pull request Dec 16, 2025
… (#66987)

The summary: we are offering drill-throughs on custom columns defined after aggregation, but those custom columns don't exist in the base query. The error presented in such a way that `lib.underlying/top-level-column` for a dimension was returning `nil`, and we were happily putting that `nil` into the query we constructed.

I created a utility to filter dimensions by whether or not the top-level-column can be resolved, and used this for the underlying-records drill-through (from the original issue) as well as the pivot drill-through (which behaved similarly). If no dimensions have a top-level column, the drill-through is not available. If some do, we offer the partial drill-through.

Co-authored-by: Timothy S. Dean <timothy.dean@metabase.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Drill-through on custom columns after aggregation fails inelegantly

3 participants

0