From 0007d0e60a05d8424003bc3965638ea1b4d9857d Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Fri, 30 Aug 2024 15:18:56 -0400 Subject: [PATCH] fix: return proper data shape when doing a read in a transaction closes #1410 --- lib/ash/actions/read/read.ex | 2 +- test/actions/read_test.exs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/ash/actions/read/read.ex b/lib/ash/actions/read/read.ex index 23beb631..7d238526 100644 --- a/lib/ash/actions/read/read.ex +++ b/lib/ash/actions/read/read.ex @@ -853,7 +853,7 @@ defmodule Ash.Actions.Read do |> case do {:error, {:error, error}} -> {:error, error} {:error, error} -> {:error, error} - {:ok, result} -> {:ok, result} + {:ok, result} -> result end query.timeout -> diff --git a/test/actions/read_test.exs b/test/actions/read_test.exs index a5596144..4bcefc24 100644 --- a/test/actions/read_test.exs +++ b/test/actions/read_test.exs @@ -31,6 +31,10 @@ defmodule Ash.Test.Actions.ReadTest do actions do default_accept :* defaults [:read, :destroy, create: :*, update: :*] + + read :in_transaction do + transaction? true + end end attributes do @@ -290,6 +294,12 @@ defmodule Ash.Test.Actions.ReadTest do end end + describe "transaction true" do + test "with no records, returns an empty set" do + assert [] = Ash.read!(Author, action: :in_transaction) + end + end + describe "Ash.read!/2 with no records" do test "returns an empty result" do assert [] = Ash.read!(Post)