Repository navigation
fix(dashboard): reconcile position_json against membership on save - #44028
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #44028 +/- ##
==========================================
- Coverage 82.80% 82.77% -0.03%
==========================================
Files 3016 3015 -1
Lines 192521 192343 -178
Branches 44842 44720 -122
==========================================
- Hits 159409 159212 -197
- Misses 30079 30099 +20
+ Partials 3033 3032 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
85e1546 to
0bccd7f
Compare
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
@aminghadersohi — ready for review (undrafted). CI green across all dialects on This reconciles dashboard It's had a 5-lens local review + an independent cross-model pass; the latter caught and closed input-hardening edge cases (malformed-JSON layout nodes, chartId=0, non-object position_json) — see the SUMMARY and the tests (both paths, soft-delete-preserved, reverted-fix control, a parameterized non-object-PUT test, and a PUT wiring test). Appreciate a look when you have a moment. |
Code Review Agent Run #33d9b5Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
fitzee
left a comment
There was a problem hiding this comment.
Adversarial review of the position_json membership reconciliation. This is a carefully written, well-tested, defensive PR — the soft-delete-bypass for valid_chart_ids, the chartId==0 handling, the bool/non-dict/malformed-node guards, doing the repair before the uuid loop, the plain-literal (non-gettext) placeholder, and both write paths all check out, and it mirrors the frontend swapUnreachableChartSlots/layoutChartId faithfully. No high-severity bug. Two secondary notes below — one edge/legacy-data regression, one redundancy. (Automated review; posted by a human reviewer.)
| chart_id | ||
| for value in positions.values() | ||
| if isinstance(value, dict) | ||
| if (chart_id := _layout_chart_id(value)) is not None |
There was a problem hiding this comment.
Edge/legacy regression: a non-int chartId (float/string) is now silently unlinked from dashboard.slices and left as an orphaned CHART node. _layout_chart_id requires isinstance(chart_id, int) (line 111), so a CHART node whose meta.chartId is 123.0 (float) or "123" (string) — from legacy data, an import, or a JSON round-trip — now returns None. The old code used value.get('meta',{}).get('chartId') with no type check, so the id landed in slice_ids and (at least for a float, and for strings on lax backends like SQLite) still resolved via Slice.id.in_(...), keeping the chart in the rebuilt dashboard.slices.
Now that node is excluded from slice_ids → the wholesale dashboard.slices = current_slices rebuild drops its dashboard_slices junction row → the chart is unlinked on the next save. And because _layout_chart_id returns None, _repair_dangling_chart_nodes also skips it, so the node isn't converted to a placeholder either — it's left as a permanent orphan CHART node no longer backed by membership. The frontend never emits non-int chartIds, so this is legacy/imported-data only, not a mainstream regression — but worth either coercing numeric chartIds (int(chart_id) when it's a float/digit-string) or logging/repairing such nodes rather than silently dropping them.
There was a problem hiding this comment.
Fixed in 7e4c47b — integral floats (123.0) and digit strings ("123") are now coerced to the int in _layout_chart_id, so a live chart in either form is recognised and kept, while an absent id in those forms is still repaired; fractional floats, non-digit strings, and bools stay None. A parametrized unit test covers every form, and a reconcile test pins the live-kept / absent-repaired split. Good catch on the orphan-tile mechanics (excluded from the rebuild AND unrepairable) — that is exactly why coercion rather than repair was the right fix.
| json.loads(position_json) | ||
| ) | ||
| positions: object = json.loads(position_json) | ||
| reconcile_position_json(positions, self._model.id) |
There was a problem hiding this comment.
Redundant reconcile whose result is discarded when a PUT also sends json_metadata.positions. When both the raw position_json field and json_metadata (which carries positions — the frontend puts them there, dashboardState.ts:754-757) are present, this path reconciles the raw field and DashboardDAO.update writes it, but set_dash_metadata then re-reconciles its own positions and overwrites dashboard.position_json (daos line ~515/388). So the work here — including the _existing_chart_ids DB query — is thrown away, and the raw position_json field is silently ignored in favor of json_metadata.positions for that save. No correctness harm (set_dash_metadata reconciles too), and the standard frontend save sends only json_metadata.positions so this path doesn't fire there — but for an API client sending both, the raw-field reconcile is dead work and the field-vs-metadata precedence is undocumented. Consider skipping the raw reconcile when json_metadata with positions is present, or noting the precedence.
There was a problem hiding this comment.
Fixed in 7e4c47b — the raw-field reconcile now runs only when json_metadata does not carry positions; when it does, set_dash_metadata reconciles and writes those and the raw field is superseded, so the dead work (including its membership query) is skipped. The precedence is recorded in the comment, json_metadata is parsed once and handed to set_dash_metadata, and an integration test pins both the precedence and that the raw reconcile is not invoked on a PUT sending both.
…c-115325) `position_json` (the layout JSON) is a plain column with no coordination against `dashboard_slices`. A chart hard-deleted while it was a live member leaves a layout node referencing an id that no longer resolves to any Slice row, and a restore-with-skips reproduces the same divergence — a layout tile pointing at a chart absent from `slices`. The divergence is invisible to the API consumer and accumulates: every save writes `meta.uuid = None` into the dangling slot. Reconcile on write: a CHART node whose chartId does not resolve to any Slice row (resolved with the soft-delete visibility filter bypassed, so recoverable soft-deleted members are preserved) is swapped in place for a markdown placeholder — keeping the node id, children, and geometry and replacing only `type`+`meta`. This mirrors the frontend `swapUnreachableChartSlots` (apache#41551) and the runtime MissingChart placeholder, persisting what the client already renders rather than re-deriving it every load. The placeholder text is a plain literal, not `gettext`: `position_json` is persisted, shared data rendered verbatim to every viewer, so translating it to the saving user's request locale would bake one language into content shown to everyone. Per-viewer localization stays the frontend's render-time job. Both write paths are covered: - `DashboardDAO.set_dash_metadata` (positions in json_metadata) — repairs using the `uuid_map` it already resolves, before the uuid-stamping loop so a repaired node is skipped there instead of getting `meta.uuid = None`. - the raw `position_json`-field PUT in `UpdateDashboardCommand.run` — reconciles via `reconcile_position_json`, which resolves membership itself. Keying on "absent from every Slice row" preserves soft-deleted members by construction and keeps `test_set_dash_metadata_preserves_soft_deleted_members` green. Tests: - unit (dao): both helper paths with live + soft-deleted + genuinely-absent chartIds; a reverted-fix control (neutering the repair fails both). - integration (api): a raw-`position_json` PUT with a dangling chartId asserts the persisted layout node is a markdown placeholder — pinning that `run()` actually invokes `reconcile_position_json` (a helper-only unit test would stay green if a refactor dropped the call). Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01267VBWbvWTNZUg9GvXKgkC
…cile when metadata carries positions fitzee review on apache#44028: - `_layout_chart_id` required `isinstance(chart_id, int)`, so a CHART node whose `meta.chartId` was `123.0` (float) or `"123"` (digit string) — legacy data, an import, a JSON round-trip — returned None. The pre-reconcile code passed those straight into `Slice.id.in_(...)`; returning None now excluded the node from the membership rebuild (unlinked on the next save) AND, with no id to resolve, skipped its repair — a permanent orphan tile. Integral floats and digit strings are now coerced to the int; fractional floats, non-digit strings, and bools stay None. Parametrized unit test covers every form; a reconcile test proves a LIVE chart referenced in either numeric form is kept while an ABSENT id in those forms is still repaired. - When a PUT sends both a raw `position_json` and `json_metadata` carrying `positions`, `set_dash_metadata` reconciles and writes the metadata positions and overwrites `position_json`, so the raw-field reconcile (including its membership query) was dead work whose result was discarded, and the precedence was undocumented. The raw reconcile now runs only when `json_metadata` does not carry positions; the precedence (metadata positions supersede the raw field) is recorded in the comment. `json_metadata` is parsed once and handed to `set_dash_metadata`. Integration test pins both the precedence and that the raw reconcile is not invoked. Rebased onto master. Unit 24/24; reconcile PUT integration tests 3/3 on Postgres. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01267VBWbvWTNZUg9GvXKgkC
0bccd7f to
0aec287
Compare
…cile when metadata carries positions fitzee review on apache#44028: - `_layout_chart_id` required `isinstance(chart_id, int)`, so a CHART node whose `meta.chartId` was `123.0` (float) or `"123"` (digit string) — legacy data, an import, a JSON round-trip — returned None. The pre-reconcile code passed those straight into `Slice.id.in_(...)`; returning None now excluded the node from the membership rebuild (unlinked on the next save) AND, with no id to resolve, skipped its repair — a permanent orphan tile. Integral floats and digit strings are now coerced to the int; fractional floats, non-digit strings, and bools stay None. Parametrized unit test covers every form; a reconcile test proves a LIVE chart referenced in either numeric form is kept while an ABSENT id in those forms is still repaired. - When a PUT sends both a raw `position_json` and `json_metadata` carrying `positions`, `set_dash_metadata` reconciles and writes the metadata positions and overwrites `position_json`, so the raw-field reconcile (including its membership query) was dead work whose result was discarded, and the precedence was undocumented. The raw reconcile now runs only when `json_metadata` does not carry positions; the precedence (metadata positions supersede the raw field) is recorded in the comment. `json_metadata` is parsed once and handed to `set_dash_metadata`. Integration test pins both the precedence and that the raw reconcile is not invoked. Rebased onto master. Unit 24/24; reconcile PUT integration tests 3/3 on Postgres. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01267VBWbvWTNZUg9GvXKgkC
0aec287 to
7e4c47b
Compare
…ull; refuse malformed CHART nodes codeant review on apache#44028, two real findings: - The precedence skip tested only for the `positions` KEY in json_metadata, but set_dash_metadata skips a null `positions` entirely (`data.get("positions") is not None`), so a PUT sending `json_metadata: {"positions": null}` alongside a raw `position_json` skipped the raw reconcile AND wrote nothing from metadata — the dangling raw layout was persisted as-is. The skip now mirrors the DAO's exact test, so the raw field is reconciled whenever metadata will not supersede it. Integration test added. - A CHART node whose `chartId` cannot be resolved was excluded from the wholesale `dashboard.slices` rebuild, silently detaching the chart it referenced. The pre-reconcile code failed that save too (a 500 from the bad `IN` value); ignoring the node is right for the REPAIR path, which never rebuilds membership, but not here. `_reject_malformed_chart_nodes` now fails the metadata path closed with a DashboardInvalidError naming the slot(s) — a 422 through the existing API mapping — before any membership is touched. Unit test (memberships untouched by the refusal) and integration test (422 naming the node, memberships intact) added. Refuted, with evidence, on the thread: the "oversized IN from a huge layout" concern — the pre-existing membership rebuild issues the identical `Slice.id.in_(slice_ids)` over the same layout ids, so the reconcile adds no new surface or bound. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01267VBWbvWTNZUg9GvXKgkC
Code Review Agent Run #e62fcaActionable Suggestions - 0Additional Suggestions - 1
Filtered by Review RulesBito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
richardfogaca
left a comment
There was a problem hiding this comment.
Richard's agent here:
Reviewed 2c3a7d9ba4b9.
P2 — copying with duplicate charts fails for a deleted-chart layout slot. copy_dashboard maps every layout chart ID through old_to_new_slice_ids.get(...); a hard-deleted chart has no mapping and becomes None. The new validation at daos/dashboard.py:526 then rejects it before reconciliation. Could we convert unmapped slots to geometry-preserving placeholders in the copy path and add a live-chart + deleted-slot copy regression test, while retaining strict save-payload validation? This is based on caller/callee and comparison-base inspection, not a runtime reproduction.
Copying a dashboard with `duplicate_slices=True` remaps every layout chart id through the clone mapping. A chart hard-deleted while it was a member has no row to clone and so no mapping entry, and the remap wrote `old_to_new_slice_ids.get(old_id)` unconditionally — turning a valid-but-dangling id into `None`. The strict malformed-node validation this PR adds then refused the copy, so a dashboard carrying such a slot could no longer be duplicated at all. Reconcile the submitted positions against the original dashboard before cloning, while the old ids still identify their rows and no clone ids exist to confuse the existence lookup. The absent slot becomes the same markdown placeholder the raw-layout path produces, keeping its node id, parent/child structure and geometry, and the remap below skips it because it no longer carries a chartId. A soft-deleted (recoverable) member is still not repaired away — `_existing_chart_ids` bypasses the visibility filter — and an originally malformed CHART node is still rejected. Reported by Richard Fogaça in review of apache#44028. Adds a copy regression covering a live chart plus a hard-deleted slot (clone referenced and uuid rewritten, placeholder geometry preserved, no null chartId, membership is the clones only, source row unmutated) and retains a negative pinning that a malformed chartId still raises. Also annotates the locals this PR added and gives the two new helpers complete one-line docstring summaries, per review. Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01267VBWbvWTNZUg9GvXKgkC
|
You're right, and thanks for catching it. The copy loop writes |
Code Review Agent Run #64e8caActionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Merge origin/master and address rusackas review findings on apache#44028. Deduplicate detached chart references before converting missing charts to placeholders, and persist integer chart IDs for native/cross-filter scope. Preserve empty legacy copy slots and document detached-slot reattachment. Add real save-path regression coverage for both supported payload forms.
|
Thanks for identifying both cases. Addressed in Chart IDs are now normalized and written back before layout repair. Detached duplicates are deduplicated while they still carry CHART identity; only remaining absent references become placeholders. The stored integer IDs are then available to both native and cross-filter scope readers. Red-first tests exercise both One deliberate legacy-slot distinction: a detached slot with a null or missing chart ID has no identity to deduplicate. This retains it as a placeholder in a reachable row, preserving its size; master previously dropped it. The existing null-slot save behavior remains supported, and the docs explicitly describe reattachment rather than claiming its detached position survives. The final focused suite has 115 passing tests, branch hooks pass, and the exact pushed tree received independent review. The PR remains draft; this is a status update on the two fixes. |
Keep the dashboard copy layout validation note alongside master's semantic bundle export guidance. Retain both auto-merged dashboard API/OpenAPI additions for the conductor's independent data-write review.
Bring in the upstream importer typing repair and current master without changing the dashboard copy or reconciliation behavior. Keep the draft branch local for exact-tree data-write review.
…json-reconcile # Conflicts: # superset/commands/dashboard/update.py
CodeAnt PR Risk: Medium Risk
Assessed commit: |
…cess part of #45535) Reduced backport of #45535 for 7.0: generate_dashboard and add_chart_to_existing_dashboard refuse charts the caller can't access (security_manager.can_access_chart), with their tests. Left out because they depend on code that only exists on master: - the layout-chart check in generate_dashboard, which needs superset.daos.dashboard._layout_chart_id from #44028, and its test_generate_dashboard_refuses_unlisted_layout_chart test; - test_chart_access_query_count.py, which calls the tool through inspect.unwrap and needs master's FastMCP 4 tool wrapping (#45639); - the docs change (docs deploy from master). (cherry picked from commit eee2c16, reduced)
…ver (access-check part of #45538) Reduced backport of #45538 for 7.0. Saving a dashboard layout (update, create, copy) refuses with a 422 a chart the layout adds that the caller can't read, since dashboard membership feeds the datasource grant for dashboard viewers (VIEWER_PROMISCUOUS_MODE) and embedded guests. Charts already on the dashboard are accepted, and a copy accepts the source's charts (or its own clones). UpdateDashboardCommand runs the check in validate(), before run() deactivates reports and emails their owners. Adapted to 7.0, which lacks the position_json reconciliation from #44028: - layout chart ids are read the way 7.0's set_dash_metadata already reads them, instead of through #44028's _layout_chart_id and _reject_malformed_chart_nodes; - DashboardLayoutInvalidError, added on master by #44028, is added here; - the archived-member adjustment and #45538's tests, which target #44028's archived handling and integration fixtures, are replaced by 7.0 unit tests covering refusal, existing members, copy, and the update pre-check. (cherry picked from commit 138a320, reduced)
…chart's own requests (reduced backport of #44215) The security manager change applies as is. On 7.0 the copy and native-filter checks build on the reduced #45538 layout check rather than master's #44028 and #45800 helpers: a copy checks the source charts it carries (all of them when duplicating or without a layout, else those its layout places) and its native-filter targets, and the update command checks new filter targets before its side effects. The dashboard datasets endpoint passes the grant to the serializer, since 7.0's DAO takes no access callback. Tests for files absent on 7.0 are left out, and 7.0's copy test now expects the refusal. (cherry picked from commit 2645396, reduced)
SUMMARY
position_json(the dashboard layout JSON) is a plain column with nocoordination against the
dashboard_slicesassociation. A chart hard-deletedwhile it was a live dashboard member leaves a layout node referencing a chart id
that no longer resolves to any
Slicerow, and a restore-with-skips reproducesthe same divergence — a layout tile pointing at a chart absent from
slices.The divergence is invisible to the API consumer and accumulates: every save
writes
meta.uuid = Noneinto the dangling slot.This reconciles
position_jsonagainst membership on write. ACHARTlayoutnode whose
chartIddoes not resolve to anySlicerow is swapped in place fora markdown placeholder — keeping the node id, children, and geometry and
replacing only
type+meta. This mirrors the frontendswapUnreachableChartSlots(#41551) and the runtime
MissingChartplaceholder, persisting what theclient already renders rather than re-deriving it on every load.
Key design decisions:
Soft-deleted members are preserved on ordinary saves. The dangling check keys on "chartId not
resolvable to any
Slicerow with the soft-delete visibility filterbypassed", so a soft-deleted (recoverable) member — whose
dashboard_slicesjunction row still exists — is never treated as dangling. Only genuinely-absent
(hard-deleted / never-existed) references are repaired. The existing
test_set_dash_metadata_preserves_soft_deleted_membersstays green.Both write paths are covered.
DashboardDAO.set_dash_metadata(positions injson_metadata, reusing its already-resolveduuid_map) and the rawposition_json-field PUT inUpdateDashboardCommand.run(which resolvesmembership itself via
reconcile_position_json).The placeholder text is a plain literal, not
gettext.position_jsonispersisted, shared data rendered verbatim to every viewer, so translating it to
the saving user's request locale would bake one language into content shown to
everyone. Per-viewer localization stays the frontend's render-time job.
Copying a dashboard AND its charts does not share archived originals. An
archived member's slot in the copy becomes a markdown placeholder saying
"This archived chart was not copied.", preserving its position and size but
dropping the chart ID/UUID and membership link. Restoring the original later
does not attach it to the copy. Live charts are still cloned; the source,
ordinary save/restore reattachment and copy-without-charts are unchanged.
Known copy limitation: a layout referencing a live chart outside the
source dashboard's membership still fails closed when copying charts. A
normal save can synchronize membership first. This PR does not choose a new
clone/placeholder policy for those nonmember slots. MCP reports this as a
source-layout repair error, which is imprecise for a membership mismatch.
The owner decision covers archived members only, not live nonmember slots.
Capacity follow-up: direct layout-ID IN lookups remain unbounded; their
previously recorded non-GA-blocking follow-up is not claimed resolved.
Refs: sc-115325. Found during the #42469 (version-restore) review but
pre-existing product-wide behavior, not a restore regression.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
No UI screenshot — this is a backend reconcile. Behaviorally: a dashboard whose
layout references a hard-deleted chart previously kept a broken
CHARTtile(
meta.uuid = null) accumulating on every save; after this change, saving swapsthat slot to a markdown "This chart no longer exists." tile (the same content the
frontend already renders at read time for such a slot).
TESTING INSTRUCTIONS
a markdown placeholder rather than a dangling
CHARTnode, andposition_jsonno longer references the absent chart id.CHARTnode with its uuid), confirming recoverable members are not repaired.Automated:
pytest tests/unit_tests/dao/dashboard_test.py(both write paths,live + soft-deleted + genuinely-absent chartIds, non-dict-
position_jsonguard,and a reverted-fix control) and
pytest tests/integration_tests/dashboards/api_tests.py -k reconciles_dangling(a PUT end-to-end pinning that
run()invokes the reconcile).Additional copy verification at
058a0ef5e0348a1305d109d81e6c999bd2bb0583:the archived-copy regression failed in both cached/fresh relationship cases
before the fix and passes after it. It runs the real restore command and checks
no reattachment to the copy, then saves the copy again. Copy-without-charts and
legacy string/float live-chart clone identity remain covered. Local affected
unit suites: 48 passed; targeted SQLite dashboard API/DAO integration:
7 passed; complete branch changed-file pre-commit passed. Full-branch Python
annotation review and independent Claude exact-snapshot review are recorded;
these local results are not a current-head CI or full-repository test claim.
ADDITIONAL INFORMATION
🤖 Generated with Claude Code