mikebridge opened a new pull request, #42469:
URL: https://github.com/apache/superset/pull/42469

   ### SUMMARY
   Adds the **write side** of entity versioning: a non-destructive 
version-restore engine and `POST 
/api/v1/{chart,dashboard,dataset}/<uuid>/versions/<version_uuid>/restore` 
endpoints. This is the backend half that `superset/versioning/api_helpers.py` 
declared "ships in a later PR" when the read side merged in #41176 — and the 
hard dependency for the version-history UI (#41551), whose Restore flow calls 
exactly these routes.
   
   Design:
   - **`superset/versioning/restore.py`** — Continuum-based restore engine 
(`restore_version`). Restore is append-only: it writes a *new* version whose 
content is the target snapshot, authored by the restoring user, so prior 
versions remain in history and the restore is itself reversible. The revert 
runs inside `single_flush_scope` (re-added to `versioning/utils.py` — it was 
dropped in the #41176 squash because this engine was its only consumer): a 
single trailing flush keeps Continuum's `Reverter` from tripping on 
mid-iteration autoflushes and keeps the whole restore in one Continuum 
transaction so the change-records listener captures it exactly once.
   - **`superset/commands/version_restore.py`** — `BaseRestoreVersionCommand` 
(lookup → `raise_for_access` with write semantics → engine call), subclassed 
per entity in `superset/commands/{chart,dashboard,dataset}/restore_version.py` 
with the entity's own not-found/forbidden/update-failed exceptions and 
`@transaction` lifecycle.
   - **API routes** on the three REST APIs, mirroring the existing versioning 
read endpoints: `@protect()` route gate plus `method_permission_name = "write"` 
(`restore_version` entries added alongside the existing soft-delete `restore` 
mapping), per-object authorization in the command. Responses carry the fresh 
version ETag via `set_version_etag_by_uuid` so clients can chain conditional 
requests.
   
   No DB migration. Everything is inert unless the operator enables versioning 
capture (`ENABLE_VERSIONING_CAPTURE`); with it off there are no versions to 
list, so restore has nothing to act on.
   
   Merge order: this PR unblocks #41551 (version-history UI), which stays draft 
until this lands. Tracked in sc-115279.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   N/A — API only.
   
   ### TESTING INSTRUCTIONS
   1. Enable `ENABLE_VERSIONING_CAPTURE = True` in config.
   2. Edit a chart a few times; `GET /api/v1/chart/<uuid>/versions/` and pick 
an older `version_uuid`.
   3. `POST /api/v1/chart/<uuid>/versions/<version_uuid>/restore` — expect 200 
with a new `ETag`; the chart's live state matches the target version, and the 
versions list has grown by one (the restore itself), not rewritten history.
   4. Repeat for dashboards and datasets.
   5. Authorization: a user without write access to the entity gets 403; 
unknown UUIDs get 404; malformed UUIDs get 400.
   
   Automated coverage: unit tests for the engine guard branch 
(`tests/unit_tests/versioning/test_restore.py`) and per-entity integration 
suites 
(`tests/integration_tests/{charts,dashboards,datasets}/version_restore_tests.py`,
 ~1,100 lines) covering happy path, permissions, cross-entity UUID mismatches, 
and restore-of-restore.
   
   ### ADDITIONAL INFORMATION
   - [x] Has associated issue: sc-115279 (Preset Shortcut); hard prerequisite 
of #41551
   - [x] Required feature flags: none new — meaningful only with 
`ENABLE_VERSIONING_CAPTURE` (config, off by default)
   - [ ] 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
   - [x] 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]

Reply via email to