ash-project / ash

A declarative, extensible framework for building Elixir applications.
https://www.ash-hq.org
MIT License
1.64k stars 220 forks source link

Complex aggregates don't pass the tenant properly #1549

Closed pshoukry closed 3 weeks ago

pshoukry commented 1 month ago

Describe the bug count :add_somthign, [:parent, :child, child2] doesn't pass the tenant properly if it was passed ot Ash.load

or any other aggregate

IT drops the tenant on the nested resources.

To Reproduce Ash.load!(:add_somthing, tenant: tenant)

Expected behavior Should run with the poper tenant

Runtime

Additional context Add any other context about the problem here.

zachdaniel commented 1 month ago

Hey @pshoukry thanks for the report, would it be possible to provide a reproduction for this issue? Either in tests or in a reproduction project? It can be difficult to reproduce the exact scenario often, and I'm quite short on time these days.

pshoukry commented 1 month ago

@zachdaniel working on that and maybe a fix if I can figure it out :)

pshoukry commented 3 weeks ago

@zachdaniel the issue mainly happens on context Multi-tenancy. so if you create for example a post with comments on tenant foo

If you have aggregate count :comments_count, [:post, :comments]

and you try to Ash.load(:comments_count, tenant: "foo")

It will sporadically select the count of comments from bar. I am using Dynamic repos with tracer to connect to multiple DBs

I am trying to figure out if this can be reproduced in ash it self or ash_postgreql. but this is the better definition I have for the problem after going through the code a bit.

I am working on a fix but sorry was a bit busy wrapping something.

pshoukry commented 3 weeks ago

This is better movied to ash_postgres