feat(storage): name the missing-tenant-schema error so callers can branch on it - #504
Merged
Merged
Conversation
…anch on it `handle_exceptions` collapses every driver exception into an anonymous `StorageError` carrying a formatted message, which erases the exception class. That is fine for the general case, but it leaves one condition unrecoverable at the caller: "the tenant schema this org addresses does not exist". The rendered text is `InvalidSchemaName: schema "org_N" does not exist`, which matches neither `isinstance(exc, psycopg2.errors.InvalidSchemaName)` (the type is gone) nor an `"invalid schema"` substring (no space in the class name). So a caller that wants to treat a vanished tenant differently from a transient fault -- e.g. park the org instead of re-querying it every few minutes -- has nothing to branch on. Adds `TenantSchemaMissingError(StorageError)`, following the existing `UserPlaybookRetentionHoldActiveError` precedent: classify at raise time, hand the caller a name. It is a subclass, so every existing `except StorageError` handler is unaffected. This is a classification, not a softening -- a missing schema for a verified org is a real provisioning failure and still logs at ERROR.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Essentials Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 5 included reviews per hour; 1 remains after this review. 📝 WalkthroughWalkthroughChangesTenant schema error classification
Priority: ⬇️ Low Estimated code review effort: 1 (Trivial) | ~5 minutes Change: Feature Merge Risk: ⚪ Minimal · up to The change adds a typed storage error while preserving existing StorageError compatibility, with no identified merge-blocking impact. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
handle_exceptionscollapses every driver exception into an anonymousStorageErrorcarrying a formatted message, which erases the exception class.That is fine for the general case, but it leaves one condition unrecoverable at
the caller: this org's tenant schema does not exist.
The rendered text is
InvalidSchemaName: schema "org_N" does not exist, whichmatches neither
isinstance(exc, psycopg2.errors.InvalidSchemaName)(the type isgone) nor an
"invalid schema"substring — there is no space in the class name.So a caller that wants to treat a vanished tenant differently from a transient
fault has nothing to branch on.
The enterprise side needs exactly that: a background sweep must park an org
whose schema is gone rather than re-querying it every few minutes. Without a
type to key on, its only options are a bare
except Exception— which wouldsuspend a healthy tenant's work on a transient blip — or substring-matching a
formatted message.
What
Adds
TenantSchemaMissingError(StorageError), following the existingUserPlaybookRetentionHoldActiveErrorprecedent: classify at raise time and handthe caller a name.
It is a subclass, so every existing
except StorageErrorhandler isunaffected. This narrows the type, it does not change the contract.
This is a classification, not a softening — a missing schema for a verified org
is a real provisioning failure and still logs at ERROR.
Verification
5040 passed, 10 skipped(unit tier), coverage 76.95%.Summary by CodeRabbit