Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/ash/resource/change/cascade_destroy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ defmodule Ash.Resource.Change.CascadeDestroy do

defp destroy_related([], _, _, _), do: :ok

defp destroy_related(data, opts, %{tenant: tenant} = context, changeset) do
defp destroy_related(data, opts, context, changeset) do
action = opts.action
relationship = opts.relationship

Expand Down Expand Up @@ -346,7 +346,8 @@ defmodule Ash.Resource.Change.CascadeDestroy do
|> List.wrap()
|> Ash.load!(
[{relationship.name, load_query}],
tenant: tenant
scope: context,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up that this function rebinds context above:

context =
Map.merge(relationship.context || %{}, %{
cascade_destroy: true,
accessing_from: %{source: relationship.source, name: relationship.name}
})

So it's missing the tenant here now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤯 good call!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not overwrite context in the first place to avoid this confusion.

authorize?: false
)
|> Enum.flat_map(fn record ->
record
Expand Down
5 changes: 3 additions & 2 deletions lib/ash/resource/change/cascade_update.ex
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ defmodule Ash.Resource.Change.CascadeUpdate do

defp update_related(_, [], _, _), do: :ok

defp update_related(changeset, data, opts, %{tenant: tenant} = context) do
defp update_related(changeset, data, opts, context) do
action = opts.action
relationship = opts.relationship
copies = opts.copy_inputs
Expand Down Expand Up @@ -260,7 +260,8 @@ defmodule Ash.Resource.Change.CascadeUpdate do
|> List.wrap()
|> Ash.load!(
[{relationship.name, load_query}],
tenant: tenant
scope: context,
authorize?: false
)
|> Enum.flat_map(fn record ->
record
Expand Down