You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "mikebridge (via GitHub)" <gi...@apache.org> on 2026/09/14 18:08:59 UTC
[PR] fix(versioning): map the restore registry guard's LookupError to 422 instead of 500 [superset]
mikebridge opened a new pull request, #44253:
URL: https://github.com/apache/superset/pull/44253
### SUMMARY
`BaseRestoreVersionCommand.run()`'s transactional wrapper kept `on_error`'s default `catches=(SQLAlchemyError,)`, so a non-DB exception from the restore engine bypassed the `failed_exc` → 422 mapping and surfaced as a raw 500. The concrete latent case (sc-115326, found in the #42469 review): `restore_version()` raises `LookupError` for a model class missing from `_RESTORE_RELATIONS` — the fail-closed registry guard. All three shipped entities are registered, so it cannot fire today; whoever wires a fourth versioned entity without a registry entry now gets the intended fail-closed 422 instead of a confusing 500.
`catches` widens to exactly `(SQLAlchemyError, LookupError)` — deliberately narrow, per the call-site comment: other non-SQLAlchemy exceptions must keep passing through the wrapper untouched so the endpoint can map specific types explicitly (e.g. #44251's fail-closed refusal).
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — error mapping. Before: unregistered model → 500 with a raw traceback. After: 422 via the entity's `failed_exc`.
### TESTING INSTRUCTIONS
`pytest tests/unit_tests/commands/test_base_restore_version_command.py` — parametrized over all three concrete commands, both directions: the registry `LookupError` maps to the subclass's `failed_exc` with the original chained as `__cause__` (fails pre-fix), and an arbitrary `RuntimeError` still propagates as itself (the tuple stays narrow).
### ADDITIONAL INFORMATION
- [x] Has associated issue: sc-115326
- [ ] 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
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(versioning): map the restore registry guard's LookupError to 422 instead of 500 [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi merged PR #44253:
URL: https://github.com/apache/superset/pull/44253
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(versioning): map the restore registry guard's LookupError to 422 instead of 500 [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #44253:
URL: https://github.com/apache/superset/pull/44253#issuecomment-5668496397
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(versioning): map the restore registry guard's LookupError to 422 instead of 500 [superset]
Posted by "mikebridge (via GitHub)" <gi...@apache.org>.
mikebridge commented on code in PR #44253:
URL: https://github.com/apache/superset/pull/44253#discussion_r4039271182
##########
superset/commands/version_restore.py:
##########
@@ -81,7 +83,20 @@ def run(self) -> RestoreResult:
# reference ``self.failed_exc`` — a per-subclass ClassVar that
# isn't available when this method is defined on the base (same
# pattern and rationale as ``BaseRestoreCommand.run``).
- @transaction(on_error=partial(on_error, reraise=self.failed_exc))
+ # ``catches`` widens past the SQLAlchemyError default so the
+ # restore engine's fail-closed registry guard (``LookupError``
+ # for a model missing from ``_RESTORE_RELATIONS``) maps to
+ # ``failed_exc`` → 422 instead of a raw 500 (sc-115326). The
+ # tuple is deliberately this narrow: other non-SQLAlchemy
+ # exceptions must keep passing through untouched for the
+ # endpoint to map explicitly.
+ @transaction(
+ on_error=partial(
+ on_error,
+ catches=(SQLAlchemyError, LookupError),
Review Comment:
I rechecked the current head (24d3f442768f376b5910f653261df8e508da0dc2) and likewise have not established a naturally reachable escaping KeyError/IndexError in this restore path. resolve_version() returns a checked fixed-arity pair; the restore registry uses .get(); Continuum version_class() catches its own KeyError. Its parent_class() lookup is unguarded, but the builder populates the reverse map alongside the forward version-class map. Malformed action metadata is caught in _inject_action_meta_record(). The 12 focused command tests pass; they test translation behavior, not proof that arbitrary internal errors are unreachable.
Would it be worth retaining the current mapping unless we can demonstrate a reachable counterexample? Choosing a dedicated registry exception to isolate future programming errors would be a separate hardening policy; I have not changed that policy or treated mock-injected KeyError as a production reproduction.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(versioning): map the restore registry guard's LookupError to 422 instead of 500 [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #44253:
URL: https://github.com/apache/superset/pull/44253#issuecomment-5694828001
<!-- Bito Reply -->
The concern regarding `LookupError` is valid in the context of the `transaction` decorator's `catches` parameter. By explicitly adding `LookupError` to the `catches` tuple in `superset/commands/version_restore.py`, the command now correctly intercepts this exception during the `_do_restore()` execution, allowing it to be re-raised as the command's `failed_exc` (typically resulting in a 422 error) rather than bubbling up as an unhandled exception (resulting in a 500 error). The implementation ensures that only `SQLAlchemyError` and `LookupError` are caught, preserving the intended behavior where other unexpected exceptions propagate through to be handled by the endpoint's global error mapping.
**superset/commands/version_restore.py**
```
@transaction(
on_error=partial(
on_error,
catches=(SQLAlchemyError, LookupError),
reraise=self.failed_exc,
)
)
```
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(versioning): map the restore registry guard's LookupError to 422 instead of 500 [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #44253:
URL: https://github.com/apache/superset/pull/44253#issuecomment-5668688011
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/44253?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 76.30%. Comparing base ([`eeafd65`](https://app.codecov.io/gh/apache/superset/commit/eeafd65b746c8cff1c424906d385fe911175661b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`24d3f44`](https://app.codecov.io/gh/apache/superset/commit/24d3f442768f376b5910f653261df8e508da0dc2?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #44253 +/- ##
=======================================
Coverage 76.29% 76.30%
=======================================
Files 2925 2925
Lines 172692 172693 +1
Branches 40090 40090
=======================================
+ Hits 131758 131772 +14
+ Misses 38247 38232 -15
- Partials 2687 2689 +2
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/44253/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [hive](https://app.codecov.io/gh/apache/superset/pull/44253/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `37.33% <0.00%> (-0.01%)` | :arrow_down: |
| [presto](https://app.codecov.io/gh/apache/superset/pull/44253/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.22% <0.00%> (-0.01%)` | :arrow_down: |
| [python](https://app.codecov.io/gh/apache/superset/pull/44253/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `76.89% <100.00%> (+0.01%)` | :arrow_up: |
| [unit](https://app.codecov.io/gh/apache/superset/pull/44253/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `75.97% <100.00%> (+0.01%)` | :arrow_up: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/44253?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(versioning): map the restore registry guard's LookupError to 422 instead of 500 [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on code in PR #44253:
URL: https://github.com/apache/superset/pull/44253#discussion_r4024251909
##########
superset/commands/version_restore.py:
##########
@@ -81,7 +83,20 @@ def run(self) -> RestoreResult:
# reference ``self.failed_exc`` — a per-subclass ClassVar that
# isn't available when this method is defined on the base (same
# pattern and rationale as ``BaseRestoreCommand.run``).
- @transaction(on_error=partial(on_error, reraise=self.failed_exc))
+ # ``catches`` widens past the SQLAlchemyError default so the
+ # restore engine's fail-closed registry guard (``LookupError``
+ # for a model missing from ``_RESTORE_RELATIONS``) maps to
+ # ``failed_exc`` → 422 instead of a raw 500 (sc-115326). The
+ # tuple is deliberately this narrow: other non-SQLAlchemy
+ # exceptions must keep passing through untouched for the
+ # endpoint to map explicitly.
+ @transaction(
+ on_error=partial(
+ on_error,
+ catches=(SQLAlchemyError, LookupError),
Review Comment:
bito's LookupError⊃KeyError/IndexError point is mechanically right, but I couldn't reach one: in _do_restore() + transaction()'s commit(), dict reads are .get()/pre-seeded, row indices fixed-arity, the change listener fail-open, and Continuum's version_class catches its own KeyError.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org