Reading Tenant ETS resources returns empty array

I am trying to read a tenanted ets resource but always getting empty list when trying to read, though creates are "successful". Below is my IEX session
Timshel.Ash.EtsComponent |> Ash.Changeset.for_create(:create, %{root: true}, tenant: "7473fdbc-4f04-4bbf-bf1f-c9721ebd18b6") |> Timshel.Ash.Api.create!()
#Timshel.Ash.EtsComponent<
organization: #Ash.NotLoaded<:relationship>,
page: #Ash.NotLoaded<:relationship>,
__meta__: #Ecto.Schema.Metadata<:loaded>,
id: "4922c76a-a6c3-4244-86fc-ca7eb7fbcd6c",
root: true,
template: nil,
name: nil,
page_id: nil,
organization_id: "7473fdbc-4f04-4bbf-bf1f-c9721ebd18b6",
aggregates: %{},
calculations: %{},
__order__: nil,
...
>
iex(test@Georges-MacBook-Pro)7> Timshel.Ash.EtsComponent |> Ash.Query.set_tenant("7473fdbc-4f04-4bbf-bf1f-c9721ebd18b6") |> Timshel.Ash.Api.read() {:ok, []}
Timshel.Ash.EtsComponent |> Ash.Changeset.for_create(:create, %{root: true}, tenant: "7473fdbc-4f04-4bbf-bf1f-c9721ebd18b6") |> Timshel.Ash.Api.create!()
#Timshel.Ash.EtsComponent<
organization: #Ash.NotLoaded<:relationship>,
page: #Ash.NotLoaded<:relationship>,
__meta__: #Ecto.Schema.Metadata<:loaded>,
id: "4922c76a-a6c3-4244-86fc-ca7eb7fbcd6c",
root: true,
template: nil,
name: nil,
page_id: nil,
organization_id: "7473fdbc-4f04-4bbf-bf1f-c9721ebd18b6",
aggregates: %{},
calculations: %{},
__order__: nil,
...
>
iex(test@Georges-MacBook-Pro)7> Timshel.Ash.EtsComponent |> Ash.Query.set_tenant("7473fdbc-4f04-4bbf-bf1f-c9721ebd18b6") |> Timshel.Ash.Api.read() {:ok, []}
5 Replies
gvanders
gvandersOP3y ago
I can see the tenant table created and can get the data out with tab2list, so issue looks to be on the read path As far as I can tell the tenant is nil on the read path, so it doesn't look in the right table. This is for attribute multitenancy, not sure about context.
ZachDaniel
ZachDaniel3y ago
Oh interesting You’re using attribute multitenancy? Ets shouldn’t be making a special table for that, which is what I think the issue is.
gvanders
gvandersOP3y ago
Yep attribute multi-tenancy For ETS, it seems like the implementation details don't really matter like they do for postgres, so maybe it's enough to make sure the tenant field in the map isn't nil? Theres some add_tenant functions which only trigger for :context
ZachDaniel
ZachDaniel3y ago
Can you open an issue in ash to remind me of this? I have a fix locally I think but have not yet verified. Will push up when I get a chance this evening or tomorrow.
gvanders
gvandersOP3y ago
GitHub
bug: Reading tenant resources fails with attribute multi-tenancy · ...
Describe the bug Presently, storing a resource with attribute tenancy for ETS happens by creating an ETS table for each tenant <> resource combo. When reading it back, tenant is not set, whic...

Did you find this page helpful?