Skip to content

feat(explore): add a dataset-level default time range - #46439

Open
efcasado wants to merge 15 commits into
apache:masterfrom
efcasado:feature/dataset-default-time-range
Open

efcasado wants to merge 15 commits into
apache:masterfrom
efcasado:feature/dataset-default-time-range

Conversation

@efcasado

@efcasado efcasado commented Nov 21, 2026 •

Copy link
Copy Markdown

SUMMARY

Note

This being my first contribution to the project, I relied on Codex and Claude to 1) get familiar with the project and its codebase, 2) validate the idea, 3) iterate on the solution, and 4) review the changes made. All changes have been reviewed and tested locally using the Docker-ized Superset environment that ships with the project, i.e. docker compose up --build; which is what has been used to capture the before and after screenshots and the animated gif.

We are Preset users and create most of our datasets from templates. Our datasets are defined on tables where an unbounded first query would be expensive and could result in the serving database getting overloaded. I was not aware of the instance-wide DEFAULT_TIME_FILTER until I started looking into this. An instance-wide DEFAULT_TIME_FILTER wouldn't work well for us, though, since the "sensible default" for our datasets is quite volatile and varies from dataset to dataset. Currently, we are solving this using run-time filters we define in SQL and apply when no filter is defined on the default datetime column.

This PR is partially related to #13125, which I believe is where this feature was first discussed. The issue was closed when #21879 was merged and added support for instance-wide DEFAULT_TIME_FILTER. I saw there was a later attempt at adding dataset-level chart defaults, i.e. #34639, which was closed and the whole discussion was put on hold and the team would "revisit how this fits in after the Semantic Layer bits all settle.". The main difference between this PR and previous attempts is that this PR doesn't add chart defaults in general. It only adds a dataset-level counterpart of DEFAULT_TIME_FILTER.

This PR adds a "Default time filter" field in Edit dataset -> Columns, right next to "Default datetime column" since they are both related. It uses the existing time range picker, and defaults to the instance's global default when unset.

Our original idea was to re-use the main_dttm_col field and turn it into something along the lines of

main_dttm_col: {column: order_date, default_time_filter: Last week}

but that would have required schema changes and a DB migration, and would have broken every API consumer and template that reads main_dttm_col as a column name. It would also have tied the default to a single column, while DEFAULT_TIME_FILTER applies to every time filter Explore adds. Thus, I decided to store the value in the dataset's extra as default_time_filter, named after DEFAULT_TIME_FILTER. This seemed to be the preferred approach in #34639. Besides the dataset editor, the default time filter can also be set in dataset import YAML or through the REST API:

# Dataset YAML in an import bundle (excerpt)
table_name: orders
main_dttm_col: order_date
extra:
  default_time_filter: Last week
PUT /api/v1/dataset/<id>
{"extra": "{\"default_time_filter\": \"Last week\"}"}

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before
dataset-level-default-time-filter-before

After
dataset-level-default-time-filter-after

Feature in action
dataset-level-default-time-filter-animated

NOTES FOR REVIEWERS

The following review notes were suggested by 🤖 Claude:

  • useDefaultTimeFilter takes an optional dataset. The filters you add yourself (dragging a column onto Filters, the filter editor), the X-axis time filter prompt and the reset after deleting the last time filter pass it, so they use the dataset's default time filter.
  • hydrateExplore gives a new chart without a time filter the dataset's default time filter. When Explore adds a time filter while opening a saved chart, getInitialTimeRange uses the instance default, so opening the chart doesn't change its query. dynamicPluginControlsReady passes the same value when a chart plugin loads late.
  • datePickerInAdhocFilterMixin (@superset-ui/chart-controls) uses the dataset's default time filter when it adds a time filter, for example after switching a chart's dataset. getDatasetDefaultTimeFilter is a new public export of that package, and ControlPanelState gains initialTimeRange, which carries the range hydration chose.
  • dndControls.tsx imports the mixins from ./mixins instead of the package index. This breaks an import cycle that left them undefined in Jest, and doesn't change behaviour in the app.
  • The filter.dateFilterControl extension contract gains an optional placeholder prop. Existing replacement pickers keep working, but they won't show "Use instance default" until they support it.
  • UpdateDatasetCommand and ImportV1DatasetSchema (in the backend) validate the value with get_since_until. An unchanged stored value isn't checked again, so it never blocks an unrelated edit. The deprecated /datasource/save/ endpoint doesn't validate it.
  • No migration and no change to UPDATING.md. Older Superset versions keep the key in extra and ignore it.
  • creating-your-first-dashboard.mdx describes the setting.

TESTING INSTRUCTIONS

  1. Edit a dataset with a datetime column, such as cleaned_sales_data. In "Columns", set "Default time filter" to a range that covers its data, e.g. from 2004-01-01 to 2005-01-01, and save.
  2. Create a new Table chart on it. The time filter on order_date starts with that range.
  3. Before editing the filters, switch the chart type to Pie. The range is kept.
  4. Drag order_date onto "Filters". The new filter uses the dataset's range. Close it without saving.
  5. Change the original time filter to "No filter", then delete it. It resets to the dataset's range instead of being removed.
  6. Switch the chart to a dataset that has a datetime column but no order_date. The time filter is re-created with that dataset's default time filter, or DEFAULT_TIME_FILTER if it has none.
  7. Open an existing saved chart on the dataset. Its filters are unchanged.
  8. Set the field to "No filter" and save: new charts start unbounded. Click "Use instance default" and save: new charts start with DEFAULT_TIME_FILTER.
  9. Send PUT /api/v1/dataset/<id> with {"extra": "{\"default_time_filter\": \"this is an invalid time range\"}"}. It's rejected with an error on extra. Importing a dataset YAML with an invalid value is rejected the same way.

ADDITIONAL INFORMATION

@github-actions github-actions Bot added doc Namespace | Anything related to documentation packages labels Nov 21, 2026
@efcasado
efcasado force-pushed the feature/dataset-default-time-range branch from 96d7dc4 to cafeeda Compare November 21, 2026 10:32
@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟡  Medium Risk

  • The PR needs attention before merging.
  • Invalid non-empty legacy time ranges are trusted, so new charts on affected datasets may fail when queried.
  • A stale or non-temporal default datetime column may still receive the dataset time filter, producing an invalid query.

Assessed commit: d9fdd943638e

@codecov

codecov Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 36.66667% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.79%. Comparing base (e017ab8) to head (4ec178f).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
superset/datasets/schemas.py 38.88% 9 Missing and 2 partials ⚠️
superset/commands/dataset/update.py 33.33% 7 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #46439      +/-   ##
==========================================
- Coverage   65.80%   65.79%   -0.01%     
==========================================
  Files        3146     3146              
  Lines      220020   220034      +14     
  Branches    52111    52107       -4     
==========================================
- Hits       144781   144772       -9     
- Misses      71807    71825      +18     
- Partials     3432     3437       +5     
Flag Coverage Δ
hive 33.63% <23.33%> (-0.01%) ⬇️
mysql 51.82% <36.66%> (-0.01%) ⬇️
postgres 51.85% <36.66%> (-0.01%) ⬇️
presto 35.32% <23.33%> (-0.01%) ⬇️
python 52.15% <36.66%> (-0.01%) ⬇️
sqlite 51.55% <36.66%> (-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.

@github-actions github-actions Bot added the i18n Namespace | Anything related to localization label Nov 21, 2026
Comment thread superset/translations/messages.pot Resolved
@efcasado
efcasado force-pushed the feature/dataset-default-time-range branch from 4d8b2c3 to 8294ff7 Compare November 21, 2026 13:46
@github-actions github-actions Bot added the requires:rebase Requires rebasing on top of current master label Nov 23, 2026
@Vitor-Avila

Copy link
Copy Markdown
Contributor

Hey @efcasado, thanks for this contribution! 🙏 I just approved the workflows, but also noticed you might need to handle some conflicts.

Small feedback on the UI portion: the "Default datetime column" dropdown is already super wide (I don't think we would have column names that big, maybe some exceptions). What do you think about having the "Default time filter" selector next to it (same line) as opposed to under it? I'm curious if that would look better.

I'm also going to share this with some folks to get a technical review on the code side.

Thanks!

@rebenitez1802 rebenitez1802 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 for this! The feature is narrow and opt-in, and I confirmed that opening an existing saved chart doesn't change its query, so CodeAnt's three comments don't hold up. I found one blocker, plus one thing to watch for when you resolve the conflict with master:

🔴 New charts created from SQL Lab lose DEFAULT_TIME_FILTER. Details and applyable fixes are in the inline comments. Please apply them together as a batch.

🟡 Resolving the messages.pot conflict: running babel_update.sh re-sorted the file and moved "Only admins can delete semantic views." and "Only admins can edit semantic views.". Master has since removed both (#46448), but git's auto-merge keeps the moved copies, and scripts/translations/check_pot_drift.py then fails with "2 string(s) in the template no longer exist in source". After merging master, re-run ./scripts/translations/babel_update.sh on the merged tree, or drop the re-sort and add just the 4 new strings by hand.

@efcasado
efcasado force-pushed the feature/dataset-default-time-range branch from 8294ff7 to 6d765e4 Compare November 26, 2026 17:53
@efcasado

Copy link
Copy Markdown
Author

Small feedback on the UI portion: the "Default datetime column" dropdown is already super wide (I don't think we would have column names that big, maybe some exceptions). What do you think about having the "Default time filter" selector next to it (same line) as opposed to under it? I'm curious if that would look better.

Thanks a lot for the feedback, @Vitor-Avila.

I will give your suggestion a try shortly and revert back.

@efcasado
efcasado force-pushed the feature/dataset-default-time-range branch from 8ed9d88 to 10eade8 Compare November 26, 2026 18:16

@rebenitez1802 rebenitez1802 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 for applying the suggestions, @efcasado! The round-1 issue is fixed: new charts opened from SQL Lab now start with the dataset's default time filter, or DEFAULT_TIME_FILTER when it has none, and saved charts open exactly as on master. The messages.pot rebase is clean too.

CI hasn't run on this commit yet (the workflows need a maintainer's approval), so I ran the checks locally: pot drift, oxlint/oxfmt, type-check, the changed frontend tests, and the dataset backend tests. All pass.

I left two optional, non-blocking suggestions inline.

Comment thread superset/datasets/schemas.py Resolved
@efcasado
efcasado force-pushed the feature/dataset-default-time-range branch 2 times, most recently from 374104d to 9d32f69 Compare November 27, 2026 17:46
@efcasado

Copy link
Copy Markdown
Author

Small feedback on the UI portion: the "Default datetime column" dropdown is already super wide (I don't think we would have column names that big, maybe some exceptions). What do you think about having the "Default time filter" selector next to it (same line) as opposed to under it? I'm curious if that would look better.

Thanks a lot for the feedback, @Vitor-Avila.

I will give your suggestion a try shortly and revert back.

@Vitor-Avila, I finally found some time to give your suggestion a try. See attached.

Screenshot 2026-11-27 at 19 09 16

If you think this version is better than the one currently implemented, I can push the changes to this PR. The different heights annoys me a bit, but it seems to stem from the style of these two components, i.e. dropdown and date picker, which have different heights. I haven't found any examples where a page would add style overrides to a component. If we are okay doing so, we could do something along the lines of

 button[name='default_time_filter'] {
   height: ${theme.sizeXL + 2 * (theme.sizeUnit + theme.lineWidth)}px;
 }

to get something along of what can be seen on the attached picture. Feel a bit hacky to me, but I don't know enough about the project 🙈

Screenshot 2026-11-27 at 19 16 55

Is this what you had in mind? Should I push these changes to the PR?

@efcasado
efcasado force-pushed the feature/dataset-default-time-range branch from 9d32f69 to 4ec178f Compare November 27, 2026 19:58
@Vitor-Avila

Copy link
Copy Markdown
Contributor

That's a good question, @efcasado! I think the UI is better this way, but I'm not sure what's the ideal method to perform this override. @rebenitez1802 what would you recommend in this case?

@rebenitez1802
rebenitez1802 self-requested a review November 27, 2026 21:42
@rebenitez1802

Copy link
Copy Markdown
Contributor

I'd go with the side-by-side version, using <Row gutter> / <Col xs={24} md={12}> like the Settings tab (around L3389) so it stacks on narrow screens.

For the height, a local override is fine. No theme token matches the Select's height, so this is a deliberate tradeoff. Just keep it in a named styled wrapper next to FieldLabelWithTooltip with a comment, so it's easy to remove if the shared components line up later:

// Mirrors the Select's rendered height; the date picker defaults to the
// compact Explore height. Remove if the two components are aligned upstream.
const DefaultTimeFilterField = styled(Flex)`
  ${({ theme }) => css`
    width: 100%;
    button[name='default_time_filter'] {
      height: ${theme.sizeXL + 2 * (theme.sizeUnit + theme.lineWidth)}px;
    }
  `}
`;

@efcasado
efcasado force-pushed the feature/dataset-default-time-range branch from b66a7a2 to 62de800 Compare November 28, 2026 07:02
@efcasado

efcasado commented Nov 28, 2026 •

Copy link
Copy Markdown
Author

@Vitor-Avila, @rebenitez1802 - Thanks for the feedback. The UI changes are ready. Indeed, this version looks more compact and polished! 🙏

Screenshot 2026-11-28 at 07 59 13 Screenshot 2026-11-28 at 07 59 08

@efcasado
efcasado force-pushed the feature/dataset-default-time-range branch from 62de800 to d4d0372 Compare November 28, 2026 07:11
@efcasado
efcasado force-pushed the feature/dataset-default-time-range branch from d4d0372 to d9fdd94 Compare November 28, 2026 11:04

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

doc Namespace | Anything related to documentation i18n Namespace | Anything related to localization packages requires:rebase Requires rebasing on top of current master size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants