Repository navigation
fix: refuse a statement for a resource without tenant_repo while its repo is bound to a tenant - #243
Closed
C-Sinclair wants to merge 2 commits into
Closed
C-Sinclair wants to merge 2 commits into
C-Sinclair wants to merge 2 commits into
Conversation
…repo is bound to a tenant `bind_tenant_repo/5` binds a tenant instance with `put_dynamic_repo/1`, and Ecto keeps that binding per repo module per process. A resource with no `tenant_repo` on the same repo module, run inside a tenant transaction, ran on the tenant database. `unbound/3` and the `nil` branch of `with_tenant_repo/4` now raise `ArgumentError` while the data layer holds that binding.
C-Sinclair
marked this pull request as ready for review
October 13, 2026 15:47
The refusal now says that a resource on its own repo module commits in its own transaction, which a rollback of the tenant transaction does not undo. A new test rolls back a tenant transaction after a `Post` write on `AshSqlite.TestRepo` and finds the `Post` row kept.
Contributor
|
@C-Sinclair I took a stab at simplifying this actually via making this a callback on the repo. Could you take a look and see what you think? It should solve this issue at compile time by requiring configuring a different repo for non-multitenant resources: https://github.com/ash-project/ash_sqlite/pull/245/changes |
Contributor
Author
Nice! That callback is much cleaner, now I see it 🧹 |
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.
There's a bug in the
tenant_repoimplementation. If you try to mix resources with the same Repo module, but only one with atenant_repoconfig, statements will land on the tenant's database.If the tenant db doens't have that table, it errors with
no such table.This is proven with a new test against
AshSqlite.Test.SharedNote: failing until the implemented fix in this PR.The fix is just to raise if the transaction spans a tenant db and another. Better to error hard rather than read/write data from the wrong place!