Skip to content

fix(mcp): exclude self-referencing filter columns from get_schema output#39826

Open
eschutho wants to merge 3 commits intomasterfrom
fix/mcp-exclude-self-referencing-filter-columns-from-schema
Open

fix(mcp): exclude self-referencing filter columns from get_schema output#39826
eschutho wants to merge 3 commits intomasterfrom
fix/mcp-exclude-self-referencing-filter-columns-from-schema

Conversation

@eschutho
Copy link
Copy Markdown
Member

@eschutho eschutho commented May 1, 2026

SUMMARY

Regression from #39638: get_schema(model_type='chart|dataset|dashboard') still advertised created_by_fk and owner in filter_columns because the chart, dataset, and dashboard ModelGetSchemaCore instances had no exclude_filter_columns set.

The LLM workflow that triggered the bug:

  1. LLM calls get_schema(model_type='chart') to discover available filter columns
  2. Response includes created_by_fk in filter_columns
  3. LLM calls get_instance_info to get current_user.id
  4. LLM calls list_charts(request={"filters": [{"col": "created_by_fk", "opr": "eq", "value": 13}]})

This bypasses the created_by_me/owned_by_me server-side injection added in #39638, re-exposing user IDs in tool calls.

Fix: pass SELF_REFERENCING_FILTER_COLUMNS as exclude_filter_columns to the chart, dataset, and dashboard ModelGetSchemaCore instances. The database schema core already had its user-directory columns excluded via DATABASE_EXCLUDE_COLUMNS.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TESTING INSTRUCTIONS

pytest tests/unit_tests/mcp_service/system/tool/test_get_schema.py -q

Manually verify get_schema no longer advertises created_by_fk or owner:

result = await client.call_tool("get_schema", {"request": {"model_type": "chart"}})
# filter_columns should NOT contain "created_by_fk" or "owner"

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration
  • Introduces new feature or API
  • Removes existing feature or API

Fixes regression introduced by #39638.

After #39638, chart/dataset/dashboard ModelGetSchemaCore instances had no
exclude_filter_columns set, so get_schema(model_type='chart|dataset|dashboard')
still advertised created_by_fk and owner in filter_columns. LLMs would call
get_schema to discover available filters, see those columns, and pass real user
IDs directly — bypassing the created_by_me/owned_by_me server-side injection
added in #39638.

Pass SELF_REFERENCING_FILTER_COLUMNS as exclude_filter_columns for chart,
dataset, and dashboard schema cores (the database core already excluded its
user-directory columns via DATABASE_EXCLUDE_COLUMNS).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented May 1, 2026

Code Review Agent Run #d63c60

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 373c366..373c366
    • superset/mcp_service/system/tool/get_schema.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

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

  • /review - 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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.89%. Comparing base (98eaaaa) to head (c0ef691).
⚠️ Report is 54 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #39826      +/-   ##
==========================================
- Coverage   64.37%   63.89%   -0.48%     
==========================================
  Files        2569     2583      +14     
  Lines      134682   136611    +1929     
  Branches    31253    31490     +237     
==========================================
+ Hits        86698    87285     +587     
- Misses      46485    47810    +1325     
- Partials     1499     1516      +17     
Flag Coverage Δ
hive 39.38% <ø> (-0.30%) ⬇️
mysql 59.06% <ø> (-0.86%) ⬇️
postgres 59.13% <ø> (-0.86%) ⬇️
presto 41.08% <ø> (-0.35%) ⬇️
python 60.57% <ø> (-0.97%) ⬇️
sqlite 58.77% <ø> (-0.86%) ⬇️
unit 100.00% <ø> (ø)

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

☔ View full report in Codecov by Sentry.
📢 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.

…d dataset

The existing test only covered dashboard. Add parallel tests for chart and
dataset to verify that created_by_fk, owner, and created_by_fk_or_owner are
excluded from filter_columns even when the DAO returns them.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@pull-request-size pull-request-size Bot added size/M and removed size/XS labels May 1, 2026
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented May 2, 2026

Code Review Agent Run #c5edd6

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 373c366..f6ef071
    • tests/unit_tests/mcp_service/system/tool/test_get_schema.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

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

  • /review - 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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@eschutho eschutho requested review from aminghadersohi and betodealmeida and removed request for betodealmeida May 4, 2026 23:55
Copy link
Copy Markdown
Contributor

@aminghadersohi aminghadersohi left a comment

Choose a reason for hiding this comment

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

The production change looks correct as defense-in-depth. Two concerns about the tests:

  1. The mocks in test_get_schema_chart_omits_self_referencing_filter_columns and the dataset equivalent only return created_by_fk and owner, which are already excluded by USER_DIRECTORY_FIELDS in ModelGetSchemaCore.__init__ (unconditionally, via self.exclude_filter_columns.update(USER_DIRECTORY_FIELDS)) — these assertions pass even without this PR's fix. To actually exercise the new exclude_filter_columns behavior, include "created_by_fk_or_owner": ["eq"] in the mock return value and assert it's absent from the output. As written, reverting the production change would not cause any of the new tests to fail.

  2. _get_dashboard_schema_core() receives the same exclude_filter_columns=set(SELF_REFERENCING_FILTER_COLUMNS) fix but has no corresponding test for self-referencing column exclusion.

Add `created_by_fk_or_owner` to the mock return values in the chart and
dataset self-referencing filter tests so the exclusion is actually exercised
(previously the assertion was vacuously true since the key was never in the
mock). Also add a matching test for the dashboard schema core, which received
the same exclude_filter_columns fix but had no corresponding coverage.
@netlify
Copy link
Copy Markdown

netlify Bot commented May 7, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit c0ef691
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/69fcb1bf065a4c0007244029
😎 Deploy Preview https://deploy-preview-39826--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.

@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented May 8, 2026

Code Review Agent Run #c78dd6

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: f6ef071..c0ef691
    • tests/unit_tests/mcp_service/system/tool/test_get_schema.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

Bito Usage Guide

Commands

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

  • /review - 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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants