Skip to content

feat(mcp): funnel chart type plugin - #43567

Open
gkneighb wants to merge 1 commit into
apache:masterfrom
gkneighb:feat/mcp-funnel-plugin
Open

gkneighb wants to merge 1 commit into
apache:masterfrom
gkneighb:feat/mcp-funnel-plugin

Conversation

@gkneighb

Copy link
Copy Markdown
Contributor

SUMMARY

Adds a generate_chart MCP plugin for the funnel chart type (viz_type: funnel), so the MCP generate_chart tool can produce funnels. Funnel is a shipped Superset viz type that had no MCP plugin; this closes that gap.

The plugin mirrors the frontend Funnel buildQuery contract: a single groupby dimension whose values become the funnel stages, plus one metric sizing each stage. When sort_by_metric is set (the frontend default), the query orders stages by the metric descending.

It follows the established plugin pattern (pie/waterfall) — a config schema, a map_*_config mapper, a plugin class, and registration:

  • FunnelChartConfig — dimension + metric required; optional sort_by_metric, row_limit (frontend default 10), filters, color_scheme. Added to the ChartConfig discriminated union and the get_chart_type_schema adapters. A dimension may not be a saved_metric/sql_expression (metric-only), matching the pie schema.
  • map_funnel_config — maps the config to form_data; saved metrics pass through as a bare name string, ad-hoc metrics as SIMPLE/SQL adhoc objects (via the shared create_metric_object).
  • FunnelChartPlugin — registered in the plugin registry; funnel was already present in the recommendation category map.

The field set is intentionally minimal (core query contract). Cosmetic controls such as label_type were deliberately left out for a follow-up — funnel's label_type is a numeric ECharts enum that needs a string→int mapping, which is out of scope here.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — backend/MCP only, no UI change.

TESTING INSTRUCTIONS

pytest tests/unit_tests/mcp_service/chart/test_funnel_chart.py — 16 unit tests cover schema validation (required fields, extra-field rejection, dimension-not-a-metric), native groupby aliasing, ChartConfig union dispatch, form_data mapping (viz_type/groupby/metric/sort/row_limit/filters/saved-metric), and registry integration (registration, resolve_viz_type, display_name, pre_validate).

To exercise end-to-end: call the generate_chart MCP tool with
{"chart_type": "funnel", "dimension": {"name": "stage"}, "metric": {"name": "leads", "aggregate": "SUM"}}.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

🤖 Generated with Claude Code

@codecov

codecov Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 44.57831% with 46 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.65%. Comparing base (1220ec0) to head (e11dfdd).
⚠️ Report is 599 commits behind head on master.

Files with missing lines Patch % Lines
superset/mcp_service/chart/plugins/funnel.py 35.71% 36 Missing ⚠️
superset/mcp_service/chart/chart_utils.py 25.00% 6 Missing ⚠️
superset/mcp_service/chart/schemas.py 73.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #43567      +/-   ##
==========================================
+ Coverage   65.62%   65.65%   +0.02%     
==========================================
  Files        3059     3060       +1     
  Lines      202434   202516      +82     
  Branches    47448    47460      +12     
==========================================
+ Hits       132852   132953     +101     
+ Misses      66587    66572      -15     
+ Partials     2995     2991       -4     
Flag Coverage Δ
hive 34.77% <44.57%> (+<0.01%) ⬆️
mysql 52.79% <44.57%> (?)
postgres 52.80% <44.57%> (-0.01%) ⬇️
presto 36.50% <44.57%> (+<0.01%) ⬆️
python 53.08% <44.57%> (+0.04%) ⬆️
sqlite 52.56% <44.57%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gkneighb
gkneighb force-pushed the feat/mcp-funnel-plugin branch from cfe6118 to a168933 Compare August 27, 2026 10:31
@gkneighb
gkneighb marked this pull request as ready for review August 27, 2026 11:18
@dosubot dosubot Bot added change:backend Requires changing the backend viz:charts:funnel Related to the Funnel chart labels Aug 27, 2026
@bito-code-review

Copy link
Copy Markdown
Contributor

The issue is valid. The map_funnel_config function in superset/mcp_service/chart/chart_utils.py currently only passes sort_by_metric as a flag in form_data, but it does not translate this into the orderby clause required by the Superset backend to actually perform the sorting. To resolve this, you should update map_funnel_config to include the orderby clause when sort_by_metric is true.

Here is the suggested fix for superset/mcp_service/chart/chart_utils.py:

    form_data: Dict[str, Any] = {
        "viz_type": "funnel",
        "groupby": [config.dimension.name],
        "metric": create_metric_object(config.metric),
        "sort_by_metric": config.sort_by_metric,
        "row_limit": config.row_limit,
        "color_scheme": config.color_scheme or "supersetColors",
    }
    if config.sort_by_metric:
        form_data["orderby"] = [[create_metric_object(config.metric), False]]
    _add_adhoc_filters(form_data, config.filters)

Would you like me to check the other comments on this PR and implement fixes for them as well?

superset/mcp_service/chart/chart_utils.py

if config.sort_by_metric:
        form_data["orderby"] = [[create_metric_object(config.metric), False]]

@bito-code-review

bito-code-review Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #2b2179

Actionable Suggestions - 0
Additional Suggestions - 2
  • superset/mcp_service/chart/chart_utils.py - 1
    • Duplicated what-builder helper · Line 1550-1556
      The new `_funnel_chart_what` (lines 1550-1556) is byte-for-byte identical to the existing `_pie_chart_what` (lines 1541-1547) — same `dimension.name` extraction, same `metric.label or metric.name or metric.sql_expression` fallback, same `f"{dim} by {metric_label}"` return. Extract a shared helper to avoid divergence if one is updated and the other is not.
  • superset/mcp_service/chart/schemas.py - 1
    • Split dimension-safety enforcement · Line 1089-1098
      The local validator docstring (line 1091) advertises that both `sql_expression` AND `saved_metric` are rejected on the dimension, but the responsibility is split between helper `_reject_sql_expression_on_dimension` and an inline check here. Two enforcement sites for the same dimension rule invite divergence if the helper later changes.
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset/mcp_service/chart/plugins/funnel.py - 1
Review Details
  • Files reviewed - 6 · Commit Range: a168933..a168933
    • superset/mcp_service/chart/chart_utils.py
    • superset/mcp_service/chart/plugins/__init__.py
    • superset/mcp_service/chart/plugins/funnel.py
    • superset/mcp_service/chart/schemas.py
    • superset/mcp_service/chart/tool/get_chart_type_schema.py
    • tests/unit_tests/mcp_service/chart/test_funnel_chart.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@aminghadersohi aminghadersohi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @gkneighb — this is the fourth MCP chart plugin in the family and it's clean, well-tested, and faithfully mirrors the existing map_pie_config structure. Comments only; nothing here blocks on its own, but two items are worth landing as a shared fix across the family rather than one-off patches.

1. Confirming the CodeAnt thread — sort_by_metric is dropped, and the mechanism is architectural (not one missing key)

The bot thread on chart_utils.py is correct at the mechanism level, and I traced it end-to-end. The MCP path builds its query context through build_query_dicts_from_form_data (superset/mcp_service/chart/chart_helpers.py:562), which reads metrics/groupby/row_limit/filters and — for everything except the bespoke deck_* branch — never emits an orderby. The frontend Funnel/buildQuery.ts is the only place that turns the flag into ordering:

...(sort_by_metric && { orderby: [[metric, false]] }),

That transform lives only in buildQuery and the MCP path does not run buildQuery, so it is silently dropped. RAN — stubbing the datasource helpers and feeding the funnel's own form_data through the canonical builder:

form_data: sort_by_metric=True
query dict: {'columns': ['stage'], 'metrics': ['SUM(leads)'], 'row_limit': 10, 'filters': []}
'orderby' in query dict: False

This is the same shape confirmed repeatedly in mcp_service this cycle (granularity_sqla, gauge bounds, radar arity, treemap grain, sankey groupby): any transformation that lives only in a frontend buildQuery is absent on the MCP path. The durable fix is to route MCP form_data through the canonical build path (or centralize a sort_by_metric → orderby step in the shared builder) once, rather than patch each plugin. Note map_pie_config (chart_utils.py:1005) already ships this exact latent no-op, so a shared fix retroactively covers pie too.

2. …but the funnel-specific user impact is narrower than the bot states — worth calibrating

The bot says "funnel stages may appear in nondeterministic order / top-stage-first is not guaranteed." For funnel specifically that overstates the display impact, because the echarts funnel series re-sorts at render time — DEFAULT_FORM_DATA.sort = 'descending' (Funnel/types.ts:73), independent of sort_by_metric. So whatever rows come back are drawn largest-first regardless. INSPECTED (transformProps.ts passes sort straight from form_data to series.sort).

The real consequence is row selection, not draw order: row_limit (default 10) becomes a LIMIT with no ORDER BY. When the dimension has ≤10 distinct values (the common funnel case: a handful of stages) → all rows returned, echarts sorts them, result is visually correct. When distinct values > 10, the DB returns 10 arbitrary rows, so the funnel can show the wrong stages entirely — a silent data-correctness bug, not a cosmetic one. So: harmless in the typical case, wrong-data in the high-cardinality case. That's the precise line to put in the fix's test.

3. aggregate on the dimension is silently accepted — same byte-identical gap as gauge/treemap/radar

reject_sql_expression_on_dimensions (schemas.py) rejects sql_expression and saved_metric on dimension, but not aggregate. RAN:

dimension={"name":"stage","aggregate":"SUM"}  -> VALIDATION PASSED
   dimension.is_metric = True
   mapped groupby = ['stage']   (aggregate silently dropped)
dimension={"name":"x","saved_metric":True}    -> REJECTED
dimension={"sql_expression":"COUNT(*)",...}    -> REJECTED

The repo already has the canonical predicate — ColumnRef.is_metric (schemas.py:751): bool(self.aggregate) or self.saved_metric or bool(self.sql_expression). Swapping the hand-rolled two-check for is_metric closes all three at once:

@model_validator(mode="after")
def reject_sql_expression_on_dimensions(self) -> "FunnelChartConfig":
    if self.dimension and self.dimension.is_metric:
        raise ValueError(
            "dimension must be a plain category column; "
            "aggregate/saved_metric/sql_expression belong in 'metric'"
        )
    return self

Severity here is low — the dimension is a single required field, aggregate is silently ignored (grouped as a plain column), so it's wrong-intent, not wrong-data. But it's the same gap now confirmed in four plugins, so it's worth fixing family-wide.

4. Negative-test coverage (Rule 26)

Mentally reverting the production files fails all 16 tests (they import the new symbols) — so the suite is coupled, not vacuous, and it's the largest test file in the family (+188). But the two gaps above are untested, and the sort_by_metric tests actively lock in the no-op:

  • test_basic_funnel_form_data / test_funnel_form_data_with_filters_and_no_sort assert form_data["sort_by_metric"] is passed through, but never assert an orderby is produced — they entrench the dropped transform (same as radar's three tests).
  • test_funnel_dimension_rejects_saved_metric exists, but there is no test asserting aggregate on the dimension is rejected.

Adding one test that the built query dict carries orderby when sort_by_metric=True, and one that aggregate-on-dimension raises, would pin both fixes.


Verification: RAN — the 16 unit tests (16 passed), plus both repros above (query-dict inspection and the aggregate/saved_metric/sql_expression validation matrix), against head a168933. INSPECTED — the frontend buildQuery.ts/transformProps.ts/types.ts and the build_query_dicts_from_form_data path. CI at post time: 46 SUCCESS / 0 pending / 0 failing (deduped by check name). Great work — happy to help wire the shared orderby + is_metric fix across the family.

@netlify

netlify Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit e11dfdd
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6adff7628ff3ffb542a1063a
😎 Deploy Preview https://deploy-preview-43567--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@aminghadersohi aminghadersohi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Round 2 — reviewed the new commit b7bab40 on top of round 1. Thanks for the quick turnaround, @gkneighb. Comments only (external contributor ceiling); one item from round 1 is fixed, one is still open.

✅ Fixed — aggregate on the dimension is now rejected

FunnelChartConfig.reject_sql_expression_on_dimensions now gates on ColumnRef.is_metric (schemas.py), which is exactly the canonical predicate. RAN at b7bab40:

dimension={"name":"stage","aggregate":"COUNT"}  -> REJECTED
   "dimension must be a plain column, not a metric ..."

and the new test_funnel_dimension_rejects_aggregate pins it. Full file: 17 passed. The explicit _reject_sql_expression_on_dimension(...) call is now technically redundant with is_metric (which already covers sql_expression), but it yields a more specific error message for the SQL case, so keeping it is fine. This closes the family-wide gap for funnel. 👍

⏳ Still open — sort_by_metric never becomes an orderby (row-limit selection bug)

This is the more serious of the two round-1 findings and is unchanged — map_funnel_config still emits sort_by_metric as a bare flag and the MCP builder never turns it into ordering. Tracked in the still-open CodeAnt thread on chart_utils.py:1032; not re-filing, just confirming it survives. RAN at b7bab40, feeding the funnel form_data through the canonical build_query_dicts_from_form_data:

query dict: {'columns': ['stage'], 'metrics': ['SUM(leads)'], 'row_limit': 10, 'filters': []}
'orderby' in query dict: False   # row_limit=10 applies as LIMIT with no ORDER BY

Consequence remains: with ≤10 distinct stages it renders correctly (echarts re-sorts descending), but with >10 distinct values you get 10 arbitrary rows, not the top-N by the metric.

⚠️ One caveat for whoever fixes this — the Bito bot on this PR suggests writing form_data["orderby"] = [[metric, False]]. That path is a no-op on the MCP builder: _build_single_query_dict builds the query entry from columns/metrics/row_limit/filters and only ever sets orderby inside the deck_* branch (chart_helpers.py:586); a top-level form_data["orderby"] is ignored. The durable fix is to add orderby to the emitted query dict (mirroring the deck-gl pattern) or to route MCP form_data through the shared build path — not to stash orderby in form_data. Same shared fix would retroactively cover map_pie_config, which has the identical latent no-op.


Verification: RAN — 17/17 unit tests and both repros (aggregate rejection + query-dict orderby absence) at head b7bab40. INSPECTED — chart_helpers.py builder path and the Bito/CodeAnt suggestions. CI at post time: 48 SUCCESS / 0 failing / 0 pending (deduped by check name). Nice work on the aggregate fix.

@bito-code-review

bito-code-review Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #52f8b6

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: a168933..b7bab40
    • superset/mcp_service/chart/schemas.py
    • tests/unit_tests/mcp_service/chart/test_funnel_chart.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@gkneighb

Copy link
Copy Markdown
Contributor Author

@aminghadersohi — fixed the still-open sort_by_metric → orderby item in eceedafe33. Per your caveat, I did not stash orderby in form_data (confirmed that's a no-op on the MCP builder); instead _build_single_query_dict now emits orderby = [(metrics[0], False)] when sort_by_metric is set — which retroactively covers the identical latent no-op in pie/treemap/sankey too. Added a query-context test asserting the built query dict carries a descending metric orderby.

@bito-code-review

bito-code-review Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #85c1d5

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: b7bab40..eceedaf
    • superset/mcp_service/chart/chart_helpers.py
    • tests/unit_tests/mcp_service/chart/test_funnel_chart.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@aminghadersohi aminghadersohi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed at eceedafe. Both prior-round findings are fixed and verified.

  • aggregate on the dimension — rejected via ColumnRef.is_metric in FunnelChartConfig (schemas.py). ✔
  • sort_by_metric → orderby — fixed in the shared _build_single_query_dict (chart_helpers.py), not in form_data (correct: the builder ignores a top-level form_data['orderby']). Verified the built query dict now carries orderby=[(metric, False)] when the flag is set, none when it's False, and the and metrics guard avoids an IndexError on metric-less queries. Same change also fixes the identical latent no-op in map_pie_config. ✔

Net-new this round: the branch now conflicts with master. The only textual conflict is in superset/mcp_service/chart/schemas.py at the ChartConfig discriminator description — HEAD adds 'funnel' to the type list, master added 'interactive_pivot'. Rebase and keep both strings; the union member itself auto-merges, only the description literal collides.

The CodeAnt thread on chart_utils.py:1032 still shows unresolved because the fix landed in chart_helpers.py rather than the anchored line — it is addressed, not outstanding.

@gkneighb
gkneighb force-pushed the feat/mcp-funnel-plugin branch from eceedaf to 1018e8a Compare August 31, 2026 15:10

@aminghadersohi aminghadersohi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed at 1018e8a. Clean — the round-3 conflict is resolved and there's nothing net-new.

  • Rebase resolved the CONFLICTING state (now MERGEABLE). The schemas.py ChartConfig discriminator description now correctly lists both 'funnel' and 'interactive_pivot' (#43480), and FunnelChartConfig remains in the union.
  • Both prior fixes survived the rebase, verified at HEAD: sort_by_metric→orderby in _build_single_query_dict (emits [(metric, False)] when the flag is set) and the ColumnRef.is_metric aggregate-on-dimension rejection.
  • New docs-only commit adds funnel to the get_chart_type_schema core-types docstring — matches the registered adapters. ✔

The CodeAnt thread on chart_utils.py (line 1059 after the rebase) is still marked unresolved but is addressed — the fix lives in _build_single_query_dict (chart_helpers.py), not the anchored mapper line.

No outstanding or new findings. CI is green; mergeStateStatus=BLOCKED reflects the required-review gate only.

@bito-code-review

bito-code-review Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #09ec02

Actionable Suggestions - 0
Additional Suggestions - 3
  • superset/mcp_service/chart/chart_helpers.py - 1
    • Reuse canonical orderby helper · Line 513-514
      This reimplements a subset of `orderby_from_form_data()` (form_data_query_context.py:174), which also respects `order_desc` (`not order_desc`) and `series_limit_metric`/`timeseries_limit_metric`. The hardcoded `False` ignores the `order_desc` already set on `qd` at line 507. Consider reusing the canonical helper to avoid divergence between the MCP and REST paths.
  • superset/mcp_service/chart/schemas.py - 2
    • Metric validation asymmetry · Line 1065-1069
      The `dimension` field rejects metrics, but `metric` has no symmetric check requiring it to actually be a metric. A plain column (no `aggregate`/`saved_metric`/`sql_expression`) passes validation and is silently coerced to SUM by `create_metric_object`. Consider rejecting `not metric.is_metric` for symmetry with the dimension validator.
    • Duplicated validator logic · Line 1089-1099
      This `reject_sql_expression_on_dimensions` validator duplicates the one in `PieChartConfig` (lines ~1036-1044) but with a subtly different check (`is_metric` vs `saved_metric` only). The divergence risk means a future fix to one may not reach the other. Consider a shared helper.
Filtered by Review Rules

Bito filtered these suggestions based on rules created automatically for your feedback. Manage rules.

  • superset/mcp_service/chart/chart_utils.py - 1
Review Details
  • Files reviewed - 7 · Commit Range: f5456af..1018e8a
    • superset/mcp_service/chart/chart_helpers.py
    • superset/mcp_service/chart/chart_utils.py
    • superset/mcp_service/chart/plugins/__init__.py
    • superset/mcp_service/chart/plugins/funnel.py
    • superset/mcp_service/chart/schemas.py
    • superset/mcp_service/chart/tool/get_chart_type_schema.py
    • tests/unit_tests/mcp_service/chart/test_funnel_chart.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@aminghadersohi

aminghadersohi commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

@gkneighb Thanks—the earlier Funnel aggregate-dimension and saved get-data ordering fixes remain correct at 1018e8a1. A fresh product-completeness pass found additional end-to-end gaps beyond those prior reviews. Could you please address or coordinate these before we count Funnel support as complete?

  1. Frontend contract: support the frontend’s ordered multi-groupby capability rather than only one typed dimension, and expose/map the meaningful percent, legend, label/tooltip, visibility, number/currency, and color controls.
  2. Native round-trip + updates: adapt actual native groupby lists and saved/SIMPLE/SQL metric shapes into FunnelChartConfig. Preserve omitted sort_by_metric, row_limit, color, filters, and presentation state across immediate, preview-first, and cached updates; explicit values and empty-filter clears must still override.
  3. Unsaved query + previews: compile/unsaved preview currently bypass the Funnel-aware shared builder, losing metric ordering under row limits. Saved preview has an approximation, while unsaved Vega drops the singular metric and ASCII falls back to a table. Add one shared Funnel representation resolving real dimension/metric aliases with consistent ordering, empty, malformed, and query-error behavior.
  4. Metric/case validation: require numeric saved/SIMPLE/SQL output, reject a metric output alias colliding with a dimension label, and fail closed on ambiguous case-insensitive column/metric/filter matches.
  5. Discovery + product tests: add Funnel to primary guidance and suitable progression-shaped recommendations. Cover generate/update/update-preview/get-data, native round-trip, ordering, and every preview format—not only mapper/registry tests.

I ran the 18 focused Funnel tests and the full MCP chart suite (1,385 passed) plus native-shape, preservation, ordering, alias/type, and ambiguity reproductions; these gaps remain with green CI. Shared builder/canonicalization/error handling from #43737 and omission-aware update work from #43679 should be reused/rebased rather than duplicated. I did not modify or push to your branch.

@rusackas

rusackas commented Sep 4, 2026

Copy link
Copy Markdown
Member

@gkneighb tempted to merge this, but wondering if you were going to address any of the (potentially) follow up work here before merging. Let us know, and thanks!

@github-actions github-actions Bot added the requires:rebase Requires rebasing on top of current master label Sep 6, 2026
@rusackas
rusackas force-pushed the feat/mcp-funnel-plugin branch from 1018e8a to de8ae20 Compare September 7, 2026 02:38
@github-actions github-actions Bot removed the requires:rebase Requires rebasing on top of current master label Sep 7, 2026
@github-actions github-actions Bot removed the requires:rebase Requires rebasing on top of current master label Sep 24, 2026

@aminghadersohi aminghadersohi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed at 061c350b: the delta vs our approved 1018e8a1 is rebase-only — the chart_helpers.py orderby fix moved to master via #43568 and still fires, so the approval premise holds. Three non-blocking inline notes; 61/61 CI legs concluded, 0 failures.

@bito-code-review bito-code-review Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review Agent Run #525973

Actionable Suggestions - 1
  • superset/mcp_service/chart/plugins/funnel.py - 1
    • CWE-1188: Loses model_fields_set on normalize · Line 99-99
Additional Suggestions - 3
  • superset/mcp_service/chart/schemas.py - 2
    • Validator name inconsistent · Line 1718-1718
      This validator rejects every metric marker on the dimension — `sql_expression` via `_reject_sql_expression_on_dimension` plus `aggregate`/`saved_metric` via `ColumnRef.is_metric` — and there is only one dimension, yet the name says `sql_expression` and plural `dimensions`. Sibling `BubbleChartConfig.reject_metric_style_dimensions` names the same job for entity/series. Rename to e.g. `reject_metric_style_dimension` so the name matches scope and count.
    • Always-true dimension guard · Line 1722-1722
      `self.dimension` is a required `ColumnRef` (`...` on the `dimension` field), and Pydantic v2 runs `mode="after"` validators only after field validation, so it is always a truthy instance here — the `self.dimension and` operand is dead. Sibling validators (`BubbleChartConfig.reject_metric_style_dimensions`) test `col.is_metric` directly. Drop the truthiness check so the code does not imply `dimension` can be absent.
  • superset/mcp_service/chart/plugins/__init__.py - 1
    • Unsorted __all__ entry · Line 81-81
      `__all__` is alphabetically sorted (BigNumber…XY), but `"FunnelChartPlugin"` sits between `PieChartPlugin` and `PivotTableChartPlugin`, breaking the ordering. The import block and `register()` calls follow alphabetical order, so this looks like an accidental insertion. Move it after `"GaugeChartPlugin"` to keep the list navigable and consistent.
Review Details
  • Files reviewed - 7 · Commit Range: 061c350..061c350
    • superset/mcp_service/chart/chart_utils.py
    • superset/mcp_service/chart/plugins/__init__.py
    • superset/mcp_service/chart/plugins/funnel.py
    • superset/mcp_service/chart/schemas.py
    • superset/mcp_service/chart/tool/generate_chart.py
    • superset/mcp_service/chart/tool/get_chart_type_schema.py
    • tests/unit_tests/mcp_service/chart/test_funnel_chart.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@rusackas

Copy link
Copy Markdown
Member

@gkneighb thanks for the PR. Holler if you want a hand addressing/resolving the latest PR review comments (human and bot ones ;)

@gkneighb
gkneighb force-pushed the feat/mcp-funnel-plugin branch from 061c350 to 235a683 Compare September 29, 2026 03:04
@gkneighb

Copy link
Copy Markdown
Contributor Author

@rusackas Thanks for the offer. Nothing outstanding here is blocking, but I did push one substantive change since your comment, at 235a683df5.

funnel.py had the same model_dump() shape you flagged on #43573, so it now uses exclude_unset=True with a test_merge_funnel_preserves_omitted_defaults regression beside the pie twin. I audited every registered plugin for it — the table is on #43573; gantt looked guilty to a grep but is actually fine.

On @aminghadersohi's three notes, all of which he marked non-blocking: the thin-coverage one is fair (every test uses the default row_limit=10 and none sets color_scheme, so mutants survive) and I'm happy to add the non-default fixture he describes if you'd like it in this PR. The other two — _funnel_chart_what being byte-identical to _pie_chart_what, and sort_by_metric resetting on update — are both pre-existing for pie as well, so I'd rather not change shared behavior under a plugin PR.

Say the word on the fixture and I'll push it; otherwise this is ready from my side.

@bito-code-review bito-code-review Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review Agent Run #ffe711

Actionable Suggestions - 1
  • superset/mcp_service/chart/schemas.py - 1
Additional Suggestions - 3
  • tests/unit_tests/mcp_service/chart/test_funnel_chart.py - 1
    • Misleading test docstring · Line 146-146
      This docstring says the MCP query builder never reads a top-level `form_data['orderby']`, but `_build_single_query_dict` does exactly that (`chart_helpers.py:740-741`). What is true is that `map_funnel_config` never emits one, so the `sort_by_metric` translation at `chart_helpers.py:753-754` carries the ordering. Reword to avoid misleading maintainers.
  • superset/mcp_service/chart/plugins/__init__.py - 1
    • Alphabetical order broken · Line 81-81
      `FunnelChartPlugin` is exported in `__all__` but placed after `PieChartPlugin`, breaking the alphabetical ordering every other entry follows (compare `BigNumberChartPlugin`...`XYChartPlugin`). This is the same ordering used by the import block, so the list reads inconsistently and future alphabetical inserts may collide with this entry. Reorder it between `GanttChartPlugin` and `HandlebarsChartPlugin`.
  • superset/mcp_service/chart/plugins/funnel.py - 1
    • Replace `Any` with specific type · Line 77-77
      Avoid using `typing.Any` in method signatures. For `extract_column_refs`, change `config: Any` to `config: FunnelChartConfig` and remove the `isinstance` check. Similar `Any` usages exist in other methods.
Review Details
  • Files reviewed - 8 · Commit Range: 235a683..235a683
    • superset/mcp_service/chart/chart_utils.py
    • superset/mcp_service/chart/plugins/__init__.py
    • superset/mcp_service/chart/plugins/funnel.py
    • superset/mcp_service/chart/schemas.py
    • superset/mcp_service/chart/tool/generate_chart.py
    • superset/mcp_service/chart/tool/get_chart_type_schema.py
    • tests/unit_tests/mcp_service/chart/test_chart_utils.py
    • tests/unit_tests/mcp_service/chart/test_funnel_chart.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

Comment thread superset/mcp_service/chart/schemas.py Outdated
Comment on lines +1721 to +1727
_reject_sql_expression_on_dimension(self.dimension, "dimension")
if self.dimension and self.dimension.is_metric:
raise ValueError(
"dimension must be a plain column, not a metric; drop "
"'aggregate'/'saved_metric' (metrics belong in the 'metric' field)"
)
return self

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Metric aggregate not validated

metric accepts a bare column ({"name": ...}, no aggregate), but create_metric_object silently defaults it to SUM and DatasetValidator._validate_aggregations skips refs without aggregate — so SUM(text_column) reaches the database as a raw DB error. GaugeChartConfig rejects non-metric refs; BubbleChartConfig.record_implicit_metric_aggregate records the implicit SUM for exactly this reason. Add the gauge-style guard here.

Code Review Run #ffe711


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

@github-actions github-actions Bot added the requires:rebase Requires rebasing on top of current master label Oct 2, 2026
@gkneighb
gkneighb force-pushed the feat/mcp-funnel-plugin branch from 235a683 to bed07ee Compare October 2, 2026 03:32
@github-actions github-actions Bot removed the requires:rebase Requires rebasing on top of current master label Oct 2, 2026

@bito-code-review bito-code-review Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review Agent Run #826fad

Actionable Suggestions - 1
  • superset/mcp_service/chart/schemas.py - 1
Additional Suggestions - 5
  • tests/unit_tests/mcp_service/chart/test_chart_utils.py - 2
    • Duplicated test scaffold · Line 163-212
      Third near-identical copy of the omitted-defaults merge test: the parametrize table, `DatasetContext` construction, existing dict and assertion match `test_merge_bubble_preserves_omitted_defaults` and `test_merge_chart_preserves_omitted_defaults` verbatim except for config/mapper lines. A shared helper parametrized over config factory and mapper would stop harness fixes from diverging across the three copies.
    • Missing explicit-None parametrize case · Line 166-171
      The pie sibling `test_merge_chart_preserves_omitted_defaults` pins a third case this table lacks: explicitly sending `color_scheme: None` must replace the saved scheme with the `map_funnel_config` default (`config.color_scheme or "supersetColors"`) instead of preserving `lyftColors`. Adding it pins the fields-set-vs-None branch for funnel, whose table already diverged from the pie copy.
  • superset/mcp_service/chart/schemas.py - 1
    • Legacy List[] typing · Line 1756-1756
      `filters: List[FilterConfig]` uses legacy `typing.List` on a newly added class. CLAUDE.md §6 mandates Python 3.10+ style (`list[str]`, `T | None`) for all new code and labels `List[...]` 'DO NOT USE'. Use `list[FilterConfig] | None` here.
  • superset/mcp_service/chart/plugins/__init__.py - 1
    • Misordered __all__ Entry · Line 81-81
      The `__all__` list is maintained in strict alphabetical order (all 15 pre-existing entries: BigNumber...XY), but the new `"FunnelChartPlugin"` entry at line 81 is inserted after `"PieChartPlugin"`, breaking the ordering. Alphabetically it belongs between `"BubbleChartPlugin"` and `"GanttChartPlugin"`. The misplaced entry impedes scanning and invites duplicate/misplaced insertions in future plugin additions.
  • superset/mcp_service/chart/plugins/funnel.py - 1
    • Missing method docstrings · Line 45-141
      BITO.md adaptive rule 12147 requires inline docstrings on every newly introduced Python function. None of the seven overrides here (`pre_validate`, `extract_column_refs`, `to_form_data`, `generate_name`, `resolve_viz_type`, `normalize_column_refs`, `schema_error_hint`) has one; the contracts they implement live only in `BaseChartPlugin`/`ChartTypePlugin` in `plugin.py`. Add one-line docstrings stating each method's funnel-specific behavior.
Review Details
  • Files reviewed - 8 · Commit Range: bed07ee..bed07ee
    • superset/mcp_service/chart/chart_utils.py
    • superset/mcp_service/chart/plugins/__init__.py
    • superset/mcp_service/chart/plugins/funnel.py
    • superset/mcp_service/chart/schemas.py
    • superset/mcp_service/chart/tool/generate_chart.py
    • superset/mcp_service/chart/tool/get_chart_type_schema.py
    • tests/unit_tests/mcp_service/chart/test_chart_utils.py
    • tests/unit_tests/mcp_service/chart/test_funnel_chart.py
  • Files skipped - 0
  • Tools
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers an incremental AI Review.

  • /review full - Manually triggers a full AI Review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

Comment thread superset/mcp_service/chart/schemas.py Outdated
Comment on lines +1746 to +1750
)
metric: ColumnRef = Field(
...,
description="Value metric sizing each stage (use aggregate e.g. SUM, "
"COUNT for ad-hoc, or set saved_metric=True for a saved dataset metric)",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Metric SUM default unvalidated

A bare metric (no aggregate/saved_metric/sql_expression) is silently summed by create_metric_object (chart_utils.py), but DatasetValidator._validate_aggregations skips refs without aggregate (dataset_validator.py:785), so SUM(text) reaches the DB on Tier-2-skipping paths. BubbleChartConfig.record_implicit_metric_aggregate guards exactly this; add the same recording here.

Code Review Run #826fad


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

@gkneighb gkneighb mentioned this pull request Oct 7, 2026
1 of 9 tasks
@gkneighb

gkneighb commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current master. CI here is down to one failing test, test_dispatchers_do_not_branch_on_registered_chart_types from #44746, flagging preview_utils: {"funnel": generate_funnel_vega_lite_preview} — which is master's own line from #44746, legal only while funnel is unregistered.

The same single test fails on all four chart-plugin PRs (#43567, #43570, #43571, #43573) for the same structural reason: that guard flags dispatcher branches keyed on registered chart types, so registering a new type is enough to turn pre-existing code into a violation. It needs the per-type behavior moved into the new plugin hooks rather than a line edit.

I've written the full analysis and two questions for @rusackas in one place to avoid four parallel threads: #43573 (comment)

Otherwise this branch is rebased, mergeable, and green.

@github-actions github-actions Bot added the requires:rebase Requires rebasing on top of current master label Oct 9, 2026
@gkneighb
gkneighb force-pushed the feat/mcp-funnel-plugin branch from bed07ee to 9317e2c Compare October 15, 2026 17:19
@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; a funnel query test checks that metric sorting produces descending ordering in the MCP query builder.

Assessed commit: e11dfdd11c85

@github-actions github-actions Bot added requires:rebase Requires rebasing on top of current master and removed requires:rebase Requires rebasing on top of current master labels Oct 15, 2026
@rusackas

Copy link
Copy Markdown
Member

I'll leave the judgement calls on the thread to @aminghadersohi but this does seem to need a conflict resolved if you can tackle that bit @gkneighb. Thanks!

@aminghadersohi
aminghadersohi self-requested a review October 21, 2026 19:22
@aminghadersohi

Copy link
Copy Markdown
Contributor

@gkneighb @rusackas thanks both. Taking the judgement calls on my threads:

  • Row-limit/color-scheme test fixture: not required. If you add it, great, but it doesn't block.
  • _funnel_chart_what duplicating _pie_chart_what: leave it. It's pre-existing and shared with pie, so a consolidation belongs in its own PR.
  • sort_by_metric resetting on update: leave it for the same reason. It's pre-existing and shared with pie, so it's a follow-up and not part of this PR.

I haven't reviewed the changes made after my last review: exclude_unset=True in funnel.py, the funnel Vega-Lite preview moved into the plugin's vega_lite_preview hook, and the emptied _FALLBACK_VEGA_RENDERERS. Once the conflict with master is resolved, I'll re-review the new head, including that the sort_by_metric → orderby fix still fires, and then this can merge.

Adds a generate_chart plugin for funnel (viz_type 'funnel'): a single
dimension defines the funnel stages, one metric sizes each stage, and
sort_by_metric orders the stages by that metric.

Redone against current master (past the gauge plugin + the gauge_chart->gauge
rename follow-up) so it applies cleanly. Ordering is applied by the shared
query-dict builder via sort_by_metric. Adds the generate_chart.py docstring
entry + the get_chart_type_schema core list.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@rusackas
rusackas force-pushed the feat/mcp-funnel-plugin branch from 9317e2c to e11dfdd Compare October 27, 2026 00:59
@rusackas

Copy link
Copy Markdown
Member

Resolved the stale threads that had already been fixed or explicitly deferred as follow-up (sort_by_metric → orderby, the CWE-1188 model_fields_set fix, and the three items @aminghadersohi already called non-blocking in the thread above). Also rebased onto current master to clear the conflict in tests/unit_tests/mcp_service/native_tool_inventory.json — that file is a generated snapshot (SUPERSET_MCP_UPDATE_TOOL_INVENTORY=1 pytest tests/unit_tests/mcp_service/test_native_tool_surface.py regenerates it), so I took a placeholder value through the rebase and I'm letting CI's own run confirm whether it needs a real regen; will follow up if that check comes back red.

One thread is still genuinely open and not just stale: FunnelChartConfig.metric has no is_metric validation, unlike dimension (which already rejects non-metric columns) and unlike GaugeChartConfig/BigNumberChartConfig. A bare column with no aggregate silently becomes SUM(...). @gkneighb, worth a look whenever you're back in here — not asking you to block on it if you'd rather leave it for a family-wide follow-up like the other two you and @aminghadersohi already parked.

@github-actions github-actions Bot added requires:rebase Requires rebasing on top of current master and removed requires:rebase Requires rebasing on top of current master labels Oct 27, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:backend Requires changing the backend requires:rebase Requires rebasing on top of current master size/XL viz:charts:funnel Related to the Funnel chart

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants