Ash FrameworkAF
Ash Framework5w ago
5 replies
MortenLund

Tenant not working for Aggregates?

Hi!

Using Ash version 3.11.1

Just discovered a strange case where the tenants not working for Ash.count/Ash.aggreate functions.

Running Ash.read(MyResource, tenant: mytenant) works.

Using Ash.count(MyResource, tenant: mytenant returns error instead:

** (Protocol.UndefinedError) protocol String.Chars not implemented for type Shared.Ash.Company.Company (a struct). This protocol is implemented for the following type(s): Ash.CiString, Atom, BitString, Cldr.Calendar.Duration, Cldr.Currency, Cldr.LanguageTag, Cldr.LanguageTag.T, Cldr.LanguageTag.U, Date, DateTime, Decimal, Float, Integer, List, NaiveDateTime, OpenApiSpex.Cast.Error, Phoenix.LiveComponent.CID, Postgrex.Copy, Postgrex.Query, Time, URI, Version, Version.Requirement

Got value:

    %Shared.Ash.Company.Company{
      id: "4c7d4bf9-1b7e-4cab-bb3f-3e23d9b75090",
    ...
   }

   (elixir 1.18.3) lib/string/chars.ex:3: String.Chars.impl_for!/1
    (elixir 1.18.3) lib/string/chars.ex:22: String.Chars.to_string/1
    (ash_postgres 2.6.26) lib/data_layer.ex:937: AshPostgres.DataLayer.set_tenant/3
    (ash 3.11.1) lib/ash/query/query.ex:4635: Ash.Query.add_tenant/2
    (ash 3.11.1) lib/ash/query/query.ex:4494: Ash.Query.data_layer_query/2
    (ash 3.11.1) lib/ash/actions/aggregate.ex:109: anonymous fn/4 in Ash.Actions.Aggregate.run/4
    (elixir 1.18.3) lib/enum.ex:4968: Enumerable.List.reduce/3
    (elixir 1.18.3) lib/enum.ex:2600: Enum.reduce_while/3
    (ash 3.11.1) lib/ash/actions/aggregate.ex:94: anonymous fn/5 in Ash.Actions.Aggregate.run/4
    (elixir 1.18.3) lib/enum.ex:4968: Enumerable.List.reduce/3
    (elixir 1.18.3) lib/enum.ex:2600: Enum.reduce_while/3
    (ash 3.11.1) lib/ash.ex:1050: Ash.aggregate/3
    (ash 3.11.1) lib/ash.ex:1116: Ash.count/2
    (ash 3.11.1) lib/ash.ex:1083: Ash.count!/2


I added an inspect in my to_tenant function and it gets called in both cases.
Was this page helpful?