aminghadersohi commented on PR #43483:
URL: https://github.com/apache/superset/pull/43483#issuecomment-6441736594

   > Hi @aminghadersohi, thanks for this PR. We run an MCP Apps chart widget on 
a Superset 6.1 fork. We hit the same problem with query rebuilding, so here is 
what worked for us.
   > 
   > **Problem:** a Python rebuild of the chart query drifts from what the 
frontend sends. It drops or reshapes options that are specific to each viz 
type: time comparison, `x_axis` with time grain, pivot post-processing, sort 
and row limits, and so on. Each plugin then needs its own patch.
   > 
   > **What we do instead:** we reuse each plugin's own `buildQuery` on the 
server.
   > 
   > 1. When the widget bundle is built, we also build a small entry point, 
`build-query.ts`. It registers the same chart preset and exposes one global 
function: `supersetBuildQuery(formDataJson)`. That function:
   >    
   >    * looks up `getChartMetadataRegistry().get(viz_type)`;
   >    * returns `{legacy: true}` when `useLegacyApi` is set, so the caller 
uses the legacy data API;
   >    * otherwise calls `getChartBuildQueryRegistry().get(viz_type)`, or 
`buildQueryContext(fd, base => [base])` when there is none, with stub hooks;
   >    * returns the `query_context` as JSON.
   > 2. On the server, we run that file once in V8 through `py_mini_racer`. We 
cache the context and guard it with a lock, because a MiniRacer context is not 
thread-safe. Then we pass the result to the normal `ChartDataCommand`.
   > 3. When the image is built, a check runs pie, a legacy viz and an unknown 
viz through the bundle, so a broken bundle fails the build and not a user 
request.
   > 
   > **Result:** the widget gets exactly the query the Explore view would send, 
for every viz type the preset registers. There is no query logic per viz type 
in Python. When a plugin's `buildQuery` changes upstream, rebuilding the bundle 
picks up the change. The cost is about 30 MB of V8 per worker and a few ms per 
call.
   > 
   > We would be happy to share the entry point and the check script, or to 
help adapt them to this PR.
   
   cc: @eschutho @rebenitez1802 


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