Skip to content

fix(native-filters): populate granularity_sqla from datasource main_dttm_col for time-range parent cascade - #39894

Open
jtjenkins wants to merge 8 commits into
apache:masterfrom
jtjenkins:fix/native-filter-granularity-sqla-cascade
Open

jtjenkins wants to merge 8 commits into
apache:masterfrom
jtjenkins:fix/native-filter-granularity-sqla-cascade

Conversation

@jtjenkins

Copy link
Copy Markdown

SUMMARY

When a native Date Range filter is configured as the parent of a Select (Value)
filter, the child filter's dropdown values should be constrained to the selected
date range. This has never worked correctly due to three bugs in FilterValue.tsx:

Bug 1 — Missing granularity_sqla: getFormData sends the parent's
time_range via extra_form_data to the child's column-values API request, but
sends no granularity_sqla. The backend receives the temporal constraint but has
no column to apply it to and silently returns all values. Upstream PR #34137 fixed
the timing (child requests now wait for parent values) but did not address the
missing column.

Bug 2 — Datasource not in Redux cache: The fix for Bug 1 reads main_dttm_col
from state.datasources, but /api/v1/dashboard/:id/datasets only returns datasets
used by chart slices. Native-filter-only datasets are never in state.datasources.
fetchDatasourceMetadata is now dispatched at mount time to populate the cache for
those datasets.

Bug 3 — Stale React closure: datasourceMainDttmCol was not in the main
useEffect dependency array. Filters with a default date range would fire their
effect before the async fetch completed and never re-run once the datasource loaded.

Changes

  • FilterValue.tsx: import fetchDatasourceMetadata
  • FilterValue.tsx: dispatch fetchDatasourceMetadata at mount when datasetId is
    set, populating state.datasources for filter-only datasets
  • FilterValue.tsx: read main_dttm_col from the cache via useSelector and use it
    as a fallback granularity_sqla when dependencies.time_range is set
  • FilterValue.tsx: add datasourceMainDttmCol to the main useEffect dep array

TESTING INSTRUCTIONS

  1. Create a dashboard with no charts (so no datasets are loaded via the slice API)
  2. Add a Time range native filter (parent)
  3. Add a Value native filter targeting a dataset that has a main_dttm_col (e.g.
    birth_names), with the Time range filter set as its parent
  4. Without a date range set: the Value filter shows all options
  5. Set a date range that contains no data in the dataset: Value filter shows "No data"
  6. Set a date range that contains a subset of the data: Value filter shows only the
    matching options
  7. Clear the date range: Value filter restores all options

ADDITIONAL INFORMATION

@bito-code-review

bito-code-review Bot commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #89855e

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 8b50b04..8b50b04
    • superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx
  • Files skipped - 0
  • Tools
    • 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 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

@dosubot dosubot Bot added the dashboard:native-filters Related to the native filters of the Dashboard label May 5, 2026
@bito-code-review

Copy link
Copy Markdown
Contributor

Yes, the suggestion is valid — the race condition can occur when multiple FilterValue components mount simultaneously, each dispatching fetchDatasourceMetadata without deduplication, leading to duplicate API requests. To resolve this, modify the fetchDatasourceMetadata thunk in src/dashboard/actions/datasources.ts to track in-flight requests using a module-level Map. There are no other comments on this PR.

superset-frontend/src/dashboard/actions/datasources.ts

const pendingFetches = new Map();

export const fetchDatasourceMetadata = (key) => (dispatch, getState) => {
  if (getState().datasources[key]) return;
  if (pendingFetches.has(key)) return;
  const promise = SupersetClient.get({ endpoint: `/superset/fetch_datasource_metadata?datasourceKey=${key}` })
    .then(data => {
      dispatch(setDatasource(key, data));
      pendingFetches.delete(key);
    })
    .catch(() => pendingFetches.delete(key));
  pendingFetches.set(key, promise);
};

…quests

When multiple FilterValue components share the same datasetId and mount
simultaneously, each sees an empty Redux cache and dispatches
fetchDatasourceMetadata. The thunk already short-circuits once the
datasource is cached, but has no guard for concurrent in-flight requests.

Add a module-level Set to track keys currently being fetched so that
parallel dispatches for the same key skip the network call. The Set entry
is cleared on both success and error so a failed request can be retried.

Addresses review feedback on the FilterValue granularity_sqla fix.

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

bito-code-review Bot commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #e7c400

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: 8b50b04..b582c8a
    • superset-frontend/src/dashboard/actions/datasources.ts
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ 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

Copilot AI 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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@rusackas

Copy link
Copy Markdown
Member

Prettier is failing on FilterValue.tsx — a quick pre-commit run prettier should sort that out and get CI green.

The state.datasources as Record<string, any> cast is the bit I'd want to lose before we merge — we're trying to get away from any, and the new main_dttm_col fallback plus the in-flight dedup Set are exactly the kind of logic I'd want a test pinning down. Can you add coverage for the cascade case?

(The playwright/cypress reds look like the usual flaky export/delete suites, not your change — don't sweat those.)

Address review feedback on the time-range parent cascade fix:

- Remove the `state.datasources as Record<string, any>` cast in
  FilterValue; state.datasources is already typed as DatasourcesState,
  so main_dttm_col resolves to string | undefined without `any`.
- Extract the granularity_sqla resolution into the pure, exported
  resolveGranularitySqla() helper and cover the cascade cases
  (own value wins, main_dttm_col fallback, no-dependency, no-dttm).
- Add datasources.test.ts covering the in-flight dedup Set: cache hit
  short-circuit, single fetch, concurrent de-duplication, and key
  cleanup after a failed request so it can retry.
- Re-run prettier on FilterValue.tsx to fix the failing format check.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Jun 23, 2026
@jtjenkins

Copy link
Copy Markdown
Author

Thanks for the review @rusackas! Addressed in 010f053:

  • Prettier — re-ran prettier on FilterValue.tsx; format check is green now.
  • as Record<string, any> cast — dropped it. state.datasources is already typed as DatasourcesState, so main_dttm_col resolves to string | undefined with no any.
  • Test coverage — pinned down both pieces of logic:
    • Extracted the granularity resolution into an exported pure resolveGranularitySqla() helper and covered the cascade cases (own value wins, main_dttm_col fallback when a time_range parent cascades, no-dependency, and no-dttm) in FilterValue.timeGrain.test.ts.
    • Added datasources.test.ts for the in-flight dedup Set: cache-hit short-circuit, single fetch, concurrent de-duplication of the same key, and key cleanup after a failed request so it can retry.

The bot's dedup suggestion was already implemented in b582c8a (the in-flight Set), so no functional change needed there — just the test pinning it down.

@netlify

netlify Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 022c541
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a3d3c2dea2e5a000840f761
😎 Deploy Preview https://deploy-preview-39894--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

bito-code-review Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #8b6135

Actionable Suggestions - 0
Review Details
  • Files reviewed - 3 · Commit Range: b582c8a..010f053
    • superset-frontend/src/dashboard/actions/datasources.test.ts
    • superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.timeGrain.test.ts
    • superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ 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

…ests

Address follow-up review feedback:

- FilterValue: the mount-time fetchDatasourceMetadata dispatch returns a
  promise that can reject (the thunk re-throws to clear its in-flight
  guard). Wrap the dispatch and log on failure so a failed best-effort
  cache prime can't surface as an unhandled promise rejection. The fetch
  is non-fatal, so the filter still works without the cascade fallback.
- datasources.test.ts: replace the `any` casts (state helper, cached
  datasource fixture, and SupersetClient.get response mocks) with proper
  types (DatasourcesState, Datasource, and the client's resolved response
  type), honoring the repo's no-`any` rule for changed TypeScript.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@bito-code-review

bito-code-review Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #91dcd4

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 010f053..3c99fa2
    • superset-frontend/src/dashboard/actions/datasources.test.ts
    • superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx
  • Files skipped - 0
  • Tools
    • Eslint (Linter) - ✔︎ 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 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

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Translation Regression Detected

A source change in this PR renamed or reworded strings, invalidating existing translations (they are now #, fuzzy) in fr. Please resolve the affected .po files before merging.

Note: intentionally deleting a translatable string is not a regression and is not flagged here — only translations invalidated by a renamed/reworded source string are.

Language Fuzzy before Fuzzy after New
fr 1004 1014 +10

How to fix

1. Install dependencies (if not already set up):

pip install -r superset/translations/requirements.txt
sudo apt-get install gettext   # or: brew install gettext

2. Re-extract strings and sync .po files:

./scripts/translations/babel_update.sh

This rewrites superset/translations/messages.pot from the current source files and merges the changes into every .po file. Strings whose msgid changed will be marked #, fuzzy.

3. Resolve the fuzzy entries in the affected language files (fr):

grep -n '#, fuzzy' superset/translations/<lang>/LC_MESSAGES/messages.po

For each fuzzy entry, either rewrite the msgstr to match the new string and remove the #, fuzzy line, or clear the msgstr to "" if you cannot provide a translation.

4. Commit your changes to the .po files.

…ranularity-sqla-cascade

# Conflicts:
#	superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx
@jtjenkins

Copy link
Copy Markdown
Author

Resolved by merging latest master (022c541). This branch was ~1048 commits behind, and the fuzzy fr entries came from source strings reworded upstream — not from this PR. The diff here touches only datasources.ts, FilterValue.tsx, and their tests, with zero t() string changes and no .po/.pot edits, so the regression was a branch-staleness artifact. Merging master brings in the already-updated fr.po. Verified locally after the merge: jest 11/11, prettier, oxlint, and tsc --noEmit all green.

Address review feedback on the dedup guard. The Set-based guard returned
`undefined` to concurrent duplicate callers, which breaks the thunk
contract: a caller awaiting the dispatch (e.g. the Promise.all over
addChart + fetchDatasourceMetadata in addSliceToDashboard) would resolve
early without the metadata and could not observe a rejection.

Replace the Set with a per-key Map of in-flight promises and return the
same promise to every concurrent caller, so completion and errors
propagate consistently. Cleanup moves to `.finally` (runs on both
success and failure). Add tests asserting concurrent callers share one
promise and that a rejection propagates to all of them.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@bito-code-review

Copy link
Copy Markdown
Contributor

AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).

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

@github-actions github-actions Bot added the requires:rebase Requires rebasing on top of current master label Aug 1, 2026
Resolve conflicts with master and address review feedback:
- fetchDatasourceMetadata: keep master's semantic-refresh path (dashboardId)
  and its new endpoint; apply the shared in-flight promise only to plain
  metadata loads; guard a missing datasources slice (datasources?.[key]).
- FilterValue: drop the applyTimeGrainAllowlist helper that master removed
  (apache#40000); only fetch dataset metadata when a time_range parent cascades,
  the filter has no granularity_sqla of its own, the dataset is a table and
  it is not already cached, so cache hits no longer dispatch setDatasource
  and remint state.datasources; catch synchronous throws from the dispatch.
- Move the resolveGranularitySqla tests to FilterValue.granularitySqla.test.ts
  (master deleted FilterValue.timeGrain.test.ts) and add FilterValue tests
  for the cascade fallback and the metadata fetch gating.

Co-Authored-By: Evan Rusackas <evan@preset.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the requires:rebase Requires rebasing on top of current master label Nov 19, 2026
@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.29730% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.67%. Comparing base (483542e) to head (daf1158).
⚠️ Report is 13 commits behind head on master.

Files with missing lines Patch % Lines
...veFilters/FilterBar/FilterControls/FilterValue.tsx 95.83% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #39894      +/-   ##
==========================================
+ Coverage   85.65%   85.67%   +0.01%     
==========================================
  Files        3108     3111       +3     
  Lines      214739   214965     +226     
  Branches    50791    50923     +132     
==========================================
+ Hits       183927   184161     +234     
+ Misses      27393    27385       -8     
  Partials     3419     3419              
Flag Coverage Δ
javascript 82.35% <97.29%> (+0.04%) ⬆️

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.

@codeant-ai-for-open-source

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; the reviewed concerns are addressed in the current code.
  • Concurrent metadata fetches share a promise, effect failures are handled, and tests cover deduplication, retries, and rejection propagation.

Assessed commit: c5fb4cc1959c

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

dashboard:native-filters Related to the native filters of the Dashboard size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants