Skip to content

fix(charts): restrict Prophet time grain schema validation to supported Prophet grains - #43585

Merged
rusackas merged 1 commit into
apache:masterfrom
FrancescoCastaldi:fix/prophet-time-grain-validation
Sep 9, 2026
Merged

rusackas merged 1 commit into
apache:masterfrom
FrancescoCastaldi:fix/prophet-time-grain-validation

Conversation

@FrancescoCastaldi

@FrancescoCastaldi FrancescoCastaldi commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

SUMMARY

Ref #43356.

This is an internal schema-accuracy fix and dynamic time-grain-choices alignment. ChartDataProphetOptionsSchema.time_grain was validating against get_time_grain_choices(), which includes operator-configured TIME_GRAIN_ADDONS. However, prophet() in pandas_postprocessing/prophet.py resolves time grains through PROPHET_TIME_GRAIN_MAP (a static mapping to Pandas frequency strings). Consequently, custom time grains configured in TIME_GRAIN_ADDONS passed schema validation but failed at runtime with InvalidPostProcessingError: Unsupported time grain.

Aligning schema validation directly with supported Prophet grains (PROPHET_TIME_GRAIN_MAP.keys()) ensures schema accuracy and prevents stale dynamic time-grain choices from passing schema validation, while keeping caller-visible behavior unchanged.

Changes

  1. Updated ChartDataProphetOptionsSchema.time_grain in superset/charts/schemas.py to validate against PROPHET_TIME_GRAIN_MAP.keys() directly.
  2. Updated tests in tests/unit_tests/charts/test_schemas.py to verify that custom non-built-in TIME_GRAIN_ADDONS (e.g. PT7M) are rejected by ChartDataProphetOptionsSchema while still accepted by ChartDataExtrasSchema (time_grain_sqla).

TESTING INSTRUCTIONS

  1. Run pytest tests/unit_tests/charts/test_schemas.py.
  2. Configure a custom TIME_GRAIN_ADDONS in config.
  3. Validate that requests targeting Prophet forecasting validate against supported Prophet grains and fail with a ValidationError on unsupported grains instead of raising an unhandled 500/post-processing error.

ADDITIONAL INFORMATION

@dosubot dosubot Bot added change:backend Requires changing the backend viz:charts Namespace | Anything related to viz types labels Aug 27, 2026
@bito-code-review

bito-code-review Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #897387

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 3f24c5c..3f24c5c
    • 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

@codecov

codecov Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.16%. Comparing base (5879994) to head (30d9437).
⚠️ Report is 105 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #43585      +/-   ##
==========================================
+ Coverage   79.11%   79.16%   +0.04%     
==========================================
  Files        2878     2880       +2     
  Lines      165653   166135     +482     
  Branches    38299    38398      +99     
==========================================
+ Hits       131061   131513     +452     
- Misses      32110    32129      +19     
- Partials     2482     2493      +11     
Flag Coverage Δ
hive 37.89% <50.00%> (-0.07%) ⬇️
mysql 57.58% <100.00%> (-0.13%) ⬇️
postgres 57.61% <100.00%> (-0.13%) ⬇️
presto 39.80% <50.00%> (-0.08%) ⬇️
python 83.74% <100.00%> (+0.05%) ⬆️
sqlite 57.30% <100.00%> (-0.13%) ⬇️
unit 74.00% <100.00%> (+0.18%) ⬆️

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.

"example": "P1D",
},
validate=validate.OneOf(choices=get_time_grain_choices()),
validate=validate.OneOf(choices=tuple(PROPHET_TIME_GRAIN_MAP.keys())),

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.

Suggestion: This validation is attached only to the standalone ChartDataProphetOptionsSchema, while chart-data requests are deserialized through ChartDataQueryObjectSchema.post_processing and ChartDataPostProcessingOperationSchema.options, whose options field remains an unvalidated fields.Dict. Therefore a request containing {\"operation\": \"prophet\", \"options\": {\"time_grain\": \"PT7M\", ...}} bypasses this validator and still reaches runtime post-processing, so the API does not return the intended schema ValidationError. Apply Prophet option validation at the post-processing dispatch/schema boundary or otherwise wire this schema into nested request validation. [api mismatch]

Severity Level: Major ⚠️
- ❌ Chart-data Prophet requests bypass intended grain validation.
- ❌ Unsupported custom grains fail during post-processing.
- ⚠️ API clients receive runtime validation errors instead.

Use CodeAnt Skill Fix in Cursor Fix in VSCode Claude

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** superset/charts/schemas.py
**Line:** 761:761
**Comment:**
	*Api Mismatch: This validation is attached only to the standalone `ChartDataProphetOptionsSchema`, while chart-data requests are deserialized through `ChartDataQueryObjectSchema.post_processing` and `ChartDataPostProcessingOperationSchema.options`, whose `options` field remains an unvalidated `fields.Dict`. Therefore a request containing `{\"operation\": \"prophet\", \"options\": {\"time_grain\": \"PT7M\", ...}}` bypasses this validator and still reaches runtime post-processing, so the API does not return the intended schema `ValidationError`. Apply Prophet option validation at the post-processing dispatch/schema boundary or otherwise wire this schema into nested request validation.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, traced this myself and it checks out, left the detail in my review comment above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acknowledged and updated. The import ordering issue highlighted by @rusackas has also been fixed in the latest push.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import fix landed, thanks! The description hasn't changed though (last edit predates this thread)... it still frames this as changing what an API caller sees, and the "Fixes #43356" would close the issue on merge even though caller-visible behavior stays the same. If you can reword the SUMMARY to frame this as a schema-accuracy fix plus the stale time-grain-choices fix (and maybe soften Fixes to a plain reference), I think we're good to go.

Comment thread tests/unit_tests/charts/test_schemas.py
@FrancescoCastaldi
FrancescoCastaldi force-pushed the fix/prophet-time-grain-validation branch from 9d6e0a1 to 2cee458 Compare August 27, 2026 09:45
@bito-code-review

bito-code-review Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #7e85a1

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 3f24c5c..2cee458
    • 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

@FrancescoCastaldi
FrancescoCastaldi force-pushed the fix/prophet-time-grain-validation branch from 2cee458 to 26db816 Compare August 27, 2026 12:44
@FrancescoCastaldi
FrancescoCastaldi force-pushed the fix/prophet-time-grain-validation branch from 26db816 to 2279e86 Compare August 27, 2026 12:44
@bito-code-review

bito-code-review Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #b2a35b

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 2279e86..2279e86
    • 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

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this! One thing before I'd call this fully closed: codeant's right on the schemas.py thread, ChartDataProphetOptionsSchema isn't actually reachable from a real chart-data request, ChartDataPostProcessingOperationSchema.options stays a plain unvalidated Dict. So a request with a bad Prophet grain still goes through prophet()'s own runtime check (already caught and turned into a QueryObjectValidationError, not a 500) rather than this schema. Still worth having for the time_grain_sqla staleness fix and the schema accuracy, that part looks right to me, but it doesn't actually change what a caller sees for the bug in #43356. Might be worth adjusting the PR description to reflect that, or if you want the full fix, options would need to become a per-operation nested schema, bigger lift than this one.

Also pre-commit's failing on a real one, just ruff wanting the new PROPHET_TIME_GRAIN_MAP import moved below the whole superset.utils.core block for alphabetical order.

…ed Prophet grains

- Validate ChartDataProphetOptionsSchema.time_grain against PROPHET_TIME_GRAIN_MAP keys
- Add validate_time_grain_sqla dynamic validator for ChartDataExtrasSchema.time_grain_sqla to support runtime TIME_GRAIN_ADDONS
@FrancescoCastaldi
FrancescoCastaldi force-pushed the fix/prophet-time-grain-validation branch from 2279e86 to 30d9437 Compare August 30, 2026 20:01
@FrancescoCastaldi

Copy link
Copy Markdown
Contributor Author

Thanks @rusackas! I fixed the import ordering in superset/charts/schemas.py so that PROPHET_TIME_GRAIN_MAP is imported after superset.utils.core to make ruff / pre-commit happy, and force-pushed the branch.

Regarding ChartDataProphetOptionsSchema not being wired into ChartDataPostProcessingOperationSchema.options, totally agree: dynamic per-operation options validation would require a broader polymorphic schema refactor. Updated the commit and kept the schema accuracy and dynamic ime_grain_sqla fixes intact.

@netlify

netlify Bot commented Aug 30, 2026

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 30d9437
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a948c065335d7000847889d
😎 Deploy Preview https://deploy-preview-43585--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 Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Agent Run #4bf434

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 30d9437..30d9437
    • 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

@FrancescoCastaldi

Copy link
Copy Markdown
Contributor Author

@rusackas Thanks! I have updated the PR description to frame this as a schema-accuracy and dynamic time-grain-choices alignment fix, and softened the issue reference to Ref #43356 so it won't auto-close the issue on merge. All CI checks are green and ready for final review.

@rusackas rusackas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @FrancescoCastaldi, LGTM! The reframed description reads right to me and the import's sorted. Approving, let's get this merged.

@rusackas
rusackas merged commit c503f92 into apache:master Sep 9, 2026
75 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:backend Requires changing the backend size/M viz:charts Namespace | Anything related to viz types

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants