Skip to content

feat(time-range-limits): add time range limits for chart queries - #46038

Open
DamianPendrak wants to merge 3 commits into
apache:masterfrom
DamianPendrak:feat/time-range-limits
Open

DamianPendrak wants to merge 3 commits into
apache:masterfrom
DamianPendrak:feat/time-range-limits

Conversation

@DamianPendrak

Copy link
Copy Markdown
Member

SUMMARY

Add time range limits for chart queries: a longest range (max_span), earliest start (max_look_back), and latest end (max_look_forward). Deployment config sets the global policy; dataset and dashboard editors can add stricter limits. The strictest applicable rule wins. TIME_RANGE_LIMITS is off by default. With it on, the server checks before cache lookup, async execution, or SQL. An out-of-range or unbounded chart query returns HTTP 400 with TIME_RANGE_LIMIT_ERROR (issue 1042); an invalid applicable stored policy fails closed with HTTP 503.

  • Explore shows limits in its time range picker and checks Run and Save. Dashboard native filters, charts, and Properties show limits, reasons, and a save check; dashboard editors receive a one-time notice when global limits turn on or tighten. Dataset editors set dataset limits. Admins get a read-only "Time range limits" page under Settings → Manage.
  • Checks also cover scheduled reports, MCP data tools, semantic-view charts, samples, time comparisons, async tasks, and cache warm-up. Reports with a refused chart send nothing. Async tasks recheck before SQL.
  • With the flag off, query enforcement and the time range limits endpoints are inactive, and existing requests without a time_range_limits key behave as before. Limit-specific write validation is bypassed, so supplied metadata can be stored unchecked. Review stored policies before turning the flag on; invalid applicable policies then fail closed.

Shared-code changes:

  • ImportExportMixin find-existing lookup helpers centralize matching for import validation, including existing rows that a policy may overwrite.
  • Time offset helpers move to common/utils/time_range_utils.py so query building and limit checks use the same offset handling.
  • Query-context and serialization paths expose and check the actual time ranges, including comparison and annotation-layer ranges, before execution.
  • Chart-data, async task, report, warm-up, datasource, and MCP entry points call the shared enforcement path so alternate query routes cannot bypass limits.
  • Dashboard/dataset APIs, import and restore commands, and audit hooks validate and record policy writes across their existing write paths; UI core adds shared range lookup and types for the picker and editors.

Upgrade: Run superset init to register the new TimeRangeLimits permission and admin menu item. No database migration is required.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Screenshot 2026-11-03 at 17 40 35 Screenshot 2026-11-03 at 16 25 40 Screenshot 2026-11-03 at 17 42 59 Screenshot 2026-11-03 at 17 42 30

TESTING INSTRUCTIONS

  1. In superset_config.py, enable FEATURE_FLAGS["TIME_RANGE_LIMITS"] = True and set TIME_RANGE_LIMITS_GLOBAL = {"schema_version": 1, "max_span": {"quantity": 3, "time_grain": "P1M"}, "max_look_back": {"quantity": 13, "time_grain": "P1M"}, "max_look_forward": {"quantity": 0, "time_grain": "P1D"}}. Restart Superset and run superset init.
  2. In a temporal dataset's Settings tab, set a stricter longest range. In a dashboard's Properties, set a stricter dashboard limit. Confirm the effective limit is the strictest and the save check lists charts/defaults it would refuse. Save, reopen, and confirm persistence.
  3. In Explore, try allowed and out-of-range dates, presets, and time comparisons. Confirm invalid ranges disable Run/Save or Apply as appropriate. On the dashboard, repeat with a native time range filter and confirm charts are held with a useful message until the filter is fixed.
  4. Open Settings → Manage → Time range limits as an admin. Confirm the global policy is read-only. A non-admin should not have access.
  5. Call chart data with an out-of-range or unbounded temporal query: expect HTTP 400, issue 1042, and no SQL. Put an invalid applicable stored policy in a test fixture: expect HTTP 503 POLICY_UNAVAILABLE. Turn the flag off and confirm chart queries are unaffected and the time range limits endpoints return 404.
  6. Run focused backend tests: pytest tests/unit_tests/utils/test_time_range_enforcement.py tests/unit_tests/utils/test_time_range_limits.py tests/unit_tests/utils/test_time_range_save_check.py tests/integration_tests/time_range_limits_tests.py. Run focused frontend tests from superset-frontend: npm run test -- timeRangeLimits.test.ts TimeRangeLimitsSection.test.tsx TimeRangeLimits.test.tsx.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags: TIME_RANGE_LIMITS
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
  • Introduces new feature or API
  • Removes existing feature or API

@netlify

netlify Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

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

@github-actions github-actions Bot added i18n Namespace | Anything related to localization api Related to the REST API doc Namespace | Anything related to documentation packages risk:chart-metadata labels Nov 5, 2026
@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.45756% with 48 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.52%. Comparing base (4cd74b8) to head (63ef518).
⚠️ Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
...mponents/DashboardBuilder/TimeRangeLimitsAlert.tsx 93.72% 18 Missing ⚠️
...c/components/TimeRangeLimits/useTimeRangeLimits.ts 90.68% 15 Missing ⚠️
...-frontend/src/dashboard/actions/timeRangeLimits.ts 97.30% 6 Missing ⚠️
...tend/src/components/TimeRangeLimits/policyDraft.ts 96.93% 3 Missing ⚠️
...src/dashboard/components/PropertiesModal/index.tsx 97.67% 2 Missing ⚠️
...ents/gridComponents/Chart/HeldChartPlaceholder.tsx 80.00% 2 Missing ⚠️
...rc/components/Datasource/DatasourceModal/index.tsx 98.11% 1 Missing ⚠️
...s/DashboardBuilder/TimeRangeLimitsEditorNotice.tsx 97.05% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #46038      +/-   ##
==========================================
+ Coverage   85.03%   85.52%   +0.48%     
==========================================
  Files        3080     3123      +43     
  Lines      209507   216959    +7452     
  Branches    49391    51388    +1997     
==========================================
+ Hits       178164   185547    +7383     
- Misses      27963    27992      +29     
- Partials     3380     3420      +40     
Flag Coverage Δ
hive 34.09% <ø> (-0.10%) ⬇️
javascript 82.15% <96.45%> (+0.77%) ⬆️
mysql 52.92% <ø> (+0.92%) ⬆️
postgres 52.94% <ø> (+0.92%) ⬆️
presto 35.71% <ø> (-0.13%) ⬇️
python 88.21% <ø> (+0.25%) ⬆️
sqlite 52.69% <ø> (+0.93%) ⬆️
superset-extensions-cli 91.24% <ø> (?)
unit 83.36% <ø> (+0.44%) ⬆️

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.

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

api Related to the REST API doc Namespace | Anything related to documentation i18n Namespace | Anything related to localization packages risk:chart-metadata

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant