Skip to content

Commit

Permalink
fix: check if in transaction before trying to roll it back
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed May 29, 2024
1 parent 1c21e39 commit 2a304a5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
20 changes: 12 additions & 8 deletions lib/ash/actions/create/bulk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1198,10 +1198,12 @@ defmodule Ash.Actions.Create.Bulk do
case Ash.Changeset.run_after_actions(result, changeset, []) do
{:error, error} ->
if opts[:transaction] && opts[:rollback_on_error?] do
Ash.DataLayer.rollback(
changeset.resource,
error
)
if Ash.DataLayer.in_transaction?(changeset.resource) do
Ash.DataLayer.rollback(
changeset.resource,
error
)
end
end

store_error(ref, error, opts)
Expand Down Expand Up @@ -1419,10 +1421,12 @@ defmodule Ash.Actions.Create.Bulk do

{:error, error} ->
if opts[:transaction] && opts[:rollback_on_error?] do
Ash.DataLayer.rollback(
resource,
error
)
if Ash.DataLayer.in_transaction?(resource) do
Ash.DataLayer.rollback(
resource,
error
)
end
end

store_error(ref, error, opts)
Expand Down
20 changes: 12 additions & 8 deletions lib/ash/actions/destroy/bulk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1820,10 +1820,12 @@ defmodule Ash.Actions.Destroy.Bulk do
case Ash.Changeset.run_after_actions(result, changeset, []) do
{:error, error} ->
if opts[:transaction] && opts[:rollback_on_error?] do
Ash.DataLayer.rollback(
changeset.resource,
error
)
if Ash.DataLayer.in_transaction?(changeset.resource) do
Ash.DataLayer.rollback(
changeset.resource,
error
)
end
end

store_error(ref, error, opts)
Expand Down Expand Up @@ -2030,10 +2032,12 @@ defmodule Ash.Actions.Destroy.Bulk do

{:error, error} ->
if opts[:transaction] && opts[:rollback_on_error?] do
Ash.DataLayer.rollback(
resource,
error
)
if Ash.DataLayer.in_transaction?(resource) do
Ash.DataLayer.rollback(
resource,
error
)
end
end

store_error(ref, error, opts)
Expand Down
20 changes: 12 additions & 8 deletions lib/ash/actions/update/bulk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2122,10 +2122,12 @@ defmodule Ash.Actions.Update.Bulk do
case Ash.Changeset.run_after_actions(result, changeset, []) do
{:error, error} ->
if opts[:transaction] && opts[:rollback_on_error?] do
Ash.DataLayer.rollback(
changeset.resource,
error
)
if Ash.DataLayer.in_transaction?(changeset.resource) do
Ash.DataLayer.rollback(
changeset.resource,
error
)
end
end

store_error(ref, error, opts)
Expand Down Expand Up @@ -2342,10 +2344,12 @@ defmodule Ash.Actions.Update.Bulk do

{:error, error} ->
if opts[:transaction] && opts[:rollback_on_error?] do
Ash.DataLayer.rollback(
resource,
error
)
if Ash.DataLayer.in_transaction?(resource) do
Ash.DataLayer.rollback(
resource,
error
)
end
end

store_error(ref, error, opts)
Expand Down

0 comments on commit 2a304a5

Please sign in to comment.