Skip to content

fix(api): advertise only the time grains Prophet can resolve - #43710

Open
SEPURI-SAI-KRISHNA wants to merge 1 commit into
apache:masterfrom
SEPURI-SAI-KRISHNA:fix/prophet-time-grain-addons
Open

fix(api): advertise only the time grains Prophet can resolve#43710
SEPURI-SAI-KRISHNA wants to merge 1 commit into
apache:masterfrom
SEPURI-SAI-KRISHNA:fix/prophet-time-grain-addons

Conversation

@SEPURI-SAI-KRISHNA

Copy link
Copy Markdown
Contributor

SUMMARY

Fixes #43356.

ChartDataProphetOptionsSchema.time_grain validates against
get_time_grain_choices(), which merges builtin_time_grains with the
operator-configured TIME_GRAIN_ADDONS. prophet() then resolves the grain
through PROPHET_TIME_GRAIN_MAP, a static map that cannot contain an
operator's arbitrary addon key. So a configured custom grain passes schema
validation and then fails at the lookup, the API advertises a forecast it
cannot serve.

Reproducing on master with TIME_GRAIN_ADDONS = {"PT7M": "7 minute"}:

PT7M is a built-in mapped grain? False
schema.load('PT7M')  : ACCEPTED
prophet('PT7M')      : InvalidPostProcessingError -> Unsupported time grain: PT7M

The addon keys are arbitrary ISO-8601 durations, so the static map cannot
simply be extended to cover them, and converting them to pandas frequencies at
runtime is not total, P0.25Y being the obvious case. That leaves the other
option the issue identifies: publish only what the operation can resolve.

This adds get_prophet_time_grain_choices(), returning the keys of
PROPHET_TIME_GRAIN_MAP, and points the Prophet field's validator at it.
get_time_grain_choices() is deliberately left alone, it is shared with
time_grain_sqla on ChartDataExtrasSchema, where addon grains are
legitimately supported, and narrowing it there would be a regression.

This widens the published set as well as narrowing it. PT0.5H
(HALF_HOUR) and P0.25Y (QUARTER_YEAR) are in the map but not in
builtin_time_grains, so they were previously rejected by the schema despite
resolving fine in prophet(). They are now accepted. Net effect on a default
deployment is 19 advertised grains -> 21, with every one of them resolvable.

No working request changes behaviour: the grains this removes from the spec
never produced a forecast.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A, backend-only fix.

TESTING INSTRUCTIONS

pytest tests/unit_tests/charts/test_schemas.py -q
pytest tests/unit_tests/pandas_postprocessing/test_prophet.py -q

Three tests are added:

  • test_prophet_schema_advertises_only_resolvable_grains asserts the field's
    own OneOf choices equal the map's keys. It reads the validator rather than
    the helper, so re-pointing the field back at get_time_grain_choices() fails
    here rather than silently reintroducing the bug.
  • test_prophet_rejects_addon_grain_accepted_by_time_grain_sqla configures
    TIME_GRAIN_ADDONS = {"PT7M": "7 minute"} and asserts the addon is still
    advertised by the shared helper while the Prophet schema rejects it. This is
    the reported bug, and it pins the "do not narrow the shared helper"
    constraint.
  • test_prophet_accepts_every_mapped_grain covers the five grains that now
    load and resolve, including the two newly advertised aliases.

The three pre-existing time_grain assertions are unchanged and still pass —
P1D remains valid and invalid_grain remains rejected.

ADDITIONAL INFORMATION

Note for reviewers: #43206 also edits ChartDataProphetOptionsSchema, about
fifty lines below this change (monthly_seasonality -> daily_seasonality,
plus index). Separate hunks, so the two should merge cleanly, but whichever
lands second may want a rebase.

@bito-code-review

bito-code-review Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Code Review Agent Run #a77d73

Actionable Suggestions - 0
Additional Suggestions - 1
  • tests/unit_tests/charts/test_schemas.py - 1
    • Misleading test name · Line 584-587
      The name/docstring claim `time_grain_sqla` accepts the addon, but its `OneOf` validator (schemas.py:1154) is evaluated at import time and frozen, so a runtime `TIME_GRAIN_ADDONS` change is not reflected in the field. The test only verifies the helper `get_time_grain_choices()`, not the field. Rename to reflect that the shared helper (not the field) includes the addon.
Review Details
  • Files reviewed - 2 · Commit Range: 29939f4..29939f4
    • superset/charts/schemas.py
    • tests/unit_tests/charts/test_schemas.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 evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@netlify

netlify Bot commented Aug 31, 2026

Copy link
Copy Markdown

Deploy Preview for superset-docs-preview ready!

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

@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.25%. Comparing base (6abab3c) to head (29939f4).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #43710   +/-   ##
=======================================
  Coverage   79.24%   79.25%           
=======================================
  Files        2888     2888           
  Lines      166446   166449    +3     
  Branches    38529    38529           
=======================================
+ Hits       131908   131911    +3     
  Misses      32045    32045           
  Partials     2493     2493           
Flag Coverage Δ
hive 37.89% <100.00%> (+<0.01%) ⬆️
mysql 57.58% <100.00%> (+<0.01%) ⬆️
postgres 57.61% <100.00%> (-0.01%) ⬇️
presto 39.80% <100.00%> (+<0.01%) ⬆️
python 83.74% <100.00%> (+<0.01%) ⬆️
sqlite 57.30% <100.00%> (+<0.01%) ⬆️
unit 74.00% <100.00%> (+<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.

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.

Custom TIME_GRAIN_ADDONS grains pass chart-data validation but fail in prophet()

1 participant