yousoph opened a new pull request, #42145:
URL: https://github.com/apache/superset/pull/42145
### SUMMARY
Enabling **Forecast** (Advanced Analytics → Predictive Analytics) on a
time-series chart could fail with an opaque 500:
```
prophet() missing 1 required positional argument: 'time_grain'
```
**Root cause:** the `prophet` post-processing op is dispatched via
`getattr(pandas_postprocessing, operation)(df, **options)` in
`QueryObject.exec_post_processing`. The frontend `prophetOperator` set
`time_grain: formData.time_grain_sqla`; when that value is `undefined` — e.g. a
saved/dashboard chart whose Time Grain control was cleared to "None", or a
chart using the generic x-axis where the grain lives on the adhoc column's
`timeGrain` popover instead of the panel control — `JSON.stringify` drops the
key. The backend then calls `prophet()` without `time_grain` and Python raises
a raw `TypeError` at call time, *before* the graceful `if not time_grain: raise
InvalidPostProcessingError(_("Time grain missing"))` guard inside `prophet()`
can run.
**Fix (both ends):**
- **Frontend (`prophetOperator.ts`):** resolve the effective time grain in
priority order — adhoc x-axis column `timeGrain` →
`queryObject.extras.time_grain_sqla` (picks up dashboard-applied grains) →
`formData.time_grain_sqla` → `P1D` fallback (matching the `time_grain_sqla`
control default in `sharedControls`), so forecasting works instead of erroring.
- **Backend (`prophet.py`):** make `time_grain` an optional kwarg
(`Optional[str] = None`), so any remaining path that can't determine a grain
surfaces the existing readable "Time grain missing"
`InvalidPostProcessingError` (422) instead of an unhandled `TypeError` (500).
No positional callers exist — the op is always dispatched with keyword options.
### BEFORE/AFTER
**Before:** forecast on a chart without `time_grain_sqla` in its form data →
HTTP 500, raw `TypeError` message shown in the chart.
**After:** the grain is resolved from the x-axis column / query extras /
form data (falling back to `P1D`) and the forecast renders; if a grain still
can't be determined server-side, the user gets a readable "Time grain missing"
error (422).
### TESTING INSTRUCTIONS
```bash
pytest tests/unit_tests/pandas_postprocessing/test_prophet.py -v
cd superset-frontend && npx jest
packages/superset-ui-chart-controls/test/operators/prophetOperator.test.ts
```
New tests:
- Backend: dispatch-path call with no `time_grain` and explicit
`time_grain=None` both raise `InvalidPostProcessingError` ("Time grain
missing") instead of `TypeError`.
- Frontend: grain resolution from adhoc x-axis column, from
`queryObject.extras`, and the `P1D` fallback when no grain is present anywhere.
To reproduce manually: save a Time-series Line Chart, clear **Time Grain**
to "None", enable **Forecast** under Advanced Analytics, run the chart.
### ADDITIONAL INFORMATION
- Fixes customer-reported issue (internal: SC-113749 / PPR-1352); follow-up
to #41180 which fixed separate errors inside prophet fitting — this failure
happened before prophet was ever invoked.
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]