Skip to content

feat(storage): name the missing-tenant-schema error so callers can branch on it - #504

Merged
guangyu-reflexio merged 1 commit into
mainfrom
fix/tenant-schema-missing-error
Sep 13, 2026
Merged

guangyu-reflexio merged 1 commit into
mainfrom
fix/tenant-schema-missing-error

Conversation

@guangyu-reflexio

@guangyu-reflexio guangyu-reflexio commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Why

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: this org's tenant schema 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 — 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 would
suspend a healthy tenant's work on a transient blip — or substring-matching a
formatted message.

What

Adds TenantSchemaMissingError(StorageError), following the existing
UserPlaybookRetentionHoldActiveError precedent: classify at raise time and hand
the caller a name.

It is a subclass, so every existing except StorageError handler is
unaffected. 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

  • Bug Fixes
    • Improved error reporting for cases where a tenant schema is missing or unavailable.
    • Preserved the specific schema-related error after storage driver errors are processed.

…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.
@coderabbitai

coderabbitai Bot commented Sep 13, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Essentials

Run ID: f3e3221c-6c38-43d8-a903-2fd00b129818

📥 Commits

Reviewing files that changed from the base of the PR and between 56fd02a and 9825afd.

📒 Files selected for processing (1)
  • reflexio/server/services/storage/error.py

Included review availability: Your plan provides up to 5 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

Changes

Tenant schema error classification

Layer / File(s) Summary
Tenant schema error contract
reflexio/server/services/storage/error.py
Adds the public TenantSchemaMissingError class as a StorageError subclass for missing or unexposed tenant schemas.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Feature

Merge Risk: ⚪ Minimal · up to 9825a

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)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a named error for missing tenant schemas so callers can branch on it.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/tenant-schema-missing-error

Comment @coderabbitai help to get the list of available commands.

@guangyu-reflexio
guangyu-reflexio merged commit bd1990a into main Sep 13, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant