How to `multitenancy :bypass` of nested/normal load

Hi, if i have a relation that has read_action which call the function which has multitenancy :bypass, i get this error
** (Ash.Error.Invalid)
Bread Crumbs:
> Error returned from: MishkaDocument.Section.read

Invalid Error

* Queries against the MishkaDocument.Section resource require a tenant to be specified
** (Ash.Error.Invalid)
Bread Crumbs:
> Error returned from: MishkaDocument.Section.read

Invalid Error

* Queries against the MishkaDocument.Section resource require a tenant to be specified
For example:
# :master_get is multitenancy :bypass
fetched_section = Ash.get!(Section, section.id, action: :master_get, authorize?: false)
section_with_workspace =
Ash.load!(fetched_section, [master_workspace_version: :master_workspace],
# tenant: fetched_section.site_id,
authorize?: false
)
# :master_get is multitenancy :bypass
fetched_section = Ash.get!(Section, section.id, action: :master_get, authorize?: false)
section_with_workspace =
Ash.load!(fetched_section, [master_workspace_version: :master_workspace],
# tenant: fetched_section.site_id,
authorize?: false
)
Relation:
belongs_to :master_workspace_version, MishkaDocument.WorkspaceVersion do
public? true
source_attribute :workspace_version_id
destination_attribute :id
read_action :read_any

description "The workspace version this section belongs to (master admin access, bypass tenant)"
end
belongs_to :master_workspace_version, MishkaDocument.WorkspaceVersion do
public? true
source_attribute :workspace_version_id
destination_attribute :id
read_action :read_any

description "The workspace version this section belongs to (master admin access, bypass tenant)"
end
This :read_any inside MishkaDocument.WorkspaceVersion is
read :read_any do
multitenancy :bypass
description "Reads all versions bypassing tenant filtering (for master relationships)"
pagination offset?: true, default_limit: 20, max_page_size: 100, countable: true
end
read :read_any do
multitenancy :bypass
description "Reads all versions bypassing tenant filtering (for master relationships)"
pagination offset?: true, default_limit: 20, max_page_size: 100, countable: true
end
How can bypass it? Thank you in advance
Solution:
So set action: :master_read on the load call as well
Jump to solution
5 Replies
ZachDaniel
ZachDaniel2mo ago
The section resource required a tenant The error message shows you which resource is telling you needs a tenant So you have to set a tenant to interact with the section
Shahryar
ShahryarOP2mo ago
Hi @Zach thank you, it shows this error when i have load! if i comment it, it dose not need tenant!! Please see my example the action has multitenancy :bypass in Section and all the relations have this too for example as you see
fetched_section =
Ash.get!(Section, section.id, action: :master_get, authorize?: false)
fetched_section =
Ash.get!(Section, section.id, action: :master_get, authorize?: false)
and the master_get is
read :master_get do
multitenancy :bypass
get? true
description "Retrieves single section by ID, bypassing tenant filtering"
end
read :master_get do
multitenancy :bypass
get? true
description "Retrieves single section by ID, bypassing tenant filtering"
end
it dose not need when i do not call load, if i load like this, i get error!
section_with_workspace =
Ash.load!(fetched_section, [master_workspace_version: :master_workspace],
# tenant: fetched_section.site_id,
authorize?: false
)
section_with_workspace =
Ash.load!(fetched_section, [master_workspace_version: :master_workspace],
# tenant: fetched_section.site_id,
authorize?: false
)
ZachDaniel
ZachDaniel2mo ago
Right, even when loading data you are using the configuration of an action
Solution
ZachDaniel
ZachDaniel2mo ago
So set action: :master_read on the load call as well
Shahryar
ShahryarOP2mo ago
So much Thank you Zach 🙏🏻

Did you find this page helpful?