Repository navigation
fix(db): scope secondary-table loaders, aliased selectables and attached objects; subqueryload works on scoped models - #822
Merged
Conversation
…mory persistent objects (#816) Tenant and soft-delete scoping now also applies to: - relationships whose secondary is a MultiTenantMixin / SoftDeleteMixin table, in joinedload, selectinload, subqueryload and joins through the relationship: the secondaryjoin carries criteria bound per execution (_secondary_scope); - Core statements on Model.__table__ before the mappers configure: tables register when the mapper is constructed; - sessions on engine.execution_options(...) or bound per model (binds=...): the engine policy resolves through the base engine (_engine_policies). Behaviour changes (TenantIsolationError): - flushing an UPDATE / DELETE of an object made persistent in memory (make_transient_to_detached, merge(load=False)) reads its row's tenant_id first and refuses a row of another tenant (_persisted_owner); - aliased(Model, <subquery or CTE>) whose selectable reads a scoped table through Core, other than the entity's own table, is refused outside all_tenants(); built from ORM entities it is scoped as before. subqueryload() no longer fails with a duplicate anon_1 alias: the selectable of an aliased entity is never cloned (#816). Claude-Session: https://claude.ai/code/session_01FXHA3ZicrtZ4C5QPEgxfgq
…re a read_sql fixture Claude-Session: https://claude.ai/code/session_01FXHA3ZicrtZ4C5QPEgxfgq
- aliased own-rows check shares the entity's own tables with the join check, so a joined-inheritance entity's subquery over its mapper's tables is allowed - the own-rows shortcut trusts only a small set of row-wise functions; any other function declines it - a missing row is not memoized by the flush owner check; a found owner still is - session_policy skips unmapped classes among the tenant models - policy bindings invalidate memoized session policies Claude-Session: https://claude.ai/code/session_01FXHA3ZicrtZ4C5QPEgxfgq
Deploying simple-module-python with
|
| Latest commit: |
03b6235
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://a5f425df.simple-module-python.pages.dev |
| Branch Preview URL: | https://fix-db-review-read-scope.simple-module-python.pages.dev |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Summary
simple_module_dbnow also covers these shapes:Relationship
secondarytables mapped byMultiTenantMixin/SoftDeleteMixinmodels, injoinedload(),selectinload(),subqueryload()and joins through the relationship. Lazy loads were already covered. Writes through the relationship skip the soft-delete condition, like every write. A bare associationTableis not filtered.aliased(Model, <Core selectable>): the selectable is read and checked. Outsideall_tenants(), three kinds of selectable raiseTenantIsolationError:The entity's own tables and plain untenanted tables stay allowed.
Objects attached detached or merged (
add()of a detached object,merge(load=False),make_transient_to_detached) are checked against the stored owner before flush. This costs one SELECT per identity, and loaded or inserted objects cost nothing.Sessions on derived engines (
engine.execution_options(...)), per-modelbinds={...}and overriddenget_bind()keep the engine's strict mode, fallback tenant and audit sink.Core statements on
Model.__table__are scoped even before any ORM use has configured the mappers.subqueryload()on scoped models no longer fails with a duplicate subquery alias.aliased()shapes above now raise;simple_module_dbnow requires SQLAlchemy ≥ 2.0.2.docs/framework/multi-tenancy.md,docs/database/mixins.md), the database skill and the CHANGELOG describe what is covered and what is refused.Verification
make lintpassed, along with these suites:make test-py: 7806 passedmake test-js: passedmake doctor: cleanframework/db/testson a disposable Postgres database: 768 passed.Closes #816
Test plan
framework/db)https://claude.ai/code/session_01FXHA3ZicrtZ4C5QPEgxfgq