SEPURI-SAI-KRISHNA opened a new pull request, #43206:
URL: https://github.com/apache/superset/pull/43206

   ### SUMMARY
   
   Two post-processing option schemas document fields that the operations they
   describe do not accept. Because `options` is passed through unvalidated, a
   client that follows the OpenAPI spec gets an HTTP 500.
   
   `QueryObject.exec_post_processing` dispatches with:
   
   ```python
   df = getattr(pandas_postprocessing, operation)(df, **options)
   ```
   
   and `ChartDataPostProcessingOperationSchema.options` is a bare `fields.Dict`.
   The per-operation schemas are therefore documentation only — nothing 
validates
   against them — so a field they publish but the function does not accept 
becomes
   `TypeError: <op>() got an unexpected keyword argument`.
   
   **`ChartDataSortOptionsSchema` is entirely out of sync with `sort()`.** It
   documents a `columns` dict — marked `required=True` — plus `aggregates`:
   
   ```python
   columns = fields.Dict(..., required=True)
   aggregates = ChartDataAggregateConfigField()
   ```
   
   while the function signature is:
   
   ```python
   def sort(df, is_sort_index=False, by=None, ascending=True) -> DataFrame:
   ```
   
   So sending exactly what the spec marks as required fails, and the three real
   parameters are undocumented:
   
   ```python
   >>> sort(df, columns={"country": True})
   TypeError: sort() got an unexpected keyword argument 'columns'
   ```
   
   The frontend `sortOperator` already sends `{is_sort_index, ascending}` or
   `{by, ascending}`, confirming which side is correct.
   
   **`ChartDataProphetOptionsSchema` documents `monthly_seasonality`**, which
   `prophet()` does not take — it takes `daily_seasonality`, which was 
undocumented,
   along with `index`:
   
   ```python
   >>> prophet(df, periods=2, confidence_interval=0.8, time_grain="P1D",
   ...         monthly_seasonality=True)
   TypeError: prophet() got an unexpected keyword argument 'monthly_seasonality'
   ```
   
   The frontend `prophetOperator` sends `daily_seasonality` and `index`, and 
never
   sends `monthly_seasonality`.
   
   This PR corrects both schemas to match their functions, and adds a test that
   walks every `ChartData*OptionsSchema`, resolves the operation it describes, 
and
   asserts each declared field is a real parameter — so the two cannot drift 
apart
   again silently.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   N/A — the change is to the OpenAPI schema definitions.
   
   ### TESTING INSTRUCTIONS
   
   ```bash
   pytest tests/unit_tests/charts/test_schemas.py
   ```
   
   `test_post_processing_option_schemas_match_their_functions` is added. 
Restoring
   either pre-fix field makes it fail with:
   
   ```
   schema fields that the post-processing function does not accept (each is a 
500
   for any client following the OpenAPI spec):
   {'ChartDataSortOptionsSchema -> sort()': ['aggregates', 'columns'],
    'ChartDataProphetOptionsSchema -> prophet()': ['monthly_seasonality']}
   ```
   
   To see the spec change, start Superset and open `/swagger/v1`, then compare 
the
   `ChartDataSortOptions` and `ChartDataProphetOptions` definitions.
   
   ### ADDITIONAL INFORMATION
   
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   ### CHECKLIST
   
   - [ ] CI checks pass
   - [x] Tests added/updated
   - [ ] Documentation updated
   - [x] PR title follows conventions
   


-- 
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]

Reply via email to