Hi all,
I have a record which I am updating using a multi, and I can get the successful return value from my function. My issue is that any following reads to the database show that the old value is still present. My understanding was that the tests run in a transaction, and all database data is available to the same processes? I have not used a different process anywhere as far as I can see. I also tried with async: true
and also false. I also tried adding read_after_writes: true
to the schema, and I tried adding returning: true
and force: true
to the Multi.update
call.
Here’s my code from my tests:
{:ok, %{job: job}} = Subject.update_job(job, %{status: "draft"})
IO.inspect({job.id, job.status})
Repo.one(from(j in HiredHippo.Jobs.Job, where: j.id == ^job.id, select: j.status))
|> IO.inspect()
HiredHippo.Recommendations.JobRecommendation
|> join(:inner, [jr], j in assoc(jr, :job))
|> where(
[jr, j],
not jr.expired and not job_application_exists(jr.candidate_id, jr.job_id, "readd") and
jr.match_percentage >= ^HiredHippo.Recommendations.MatchPercentage.base_match() and
j.status == "published" and not j.archived
)
|> select([jr, j], {jr.id, j.id, jr.expired, j.archived, j.status})
|> Repo.all()
|> IO.inspect()
What I am seeing, is that the first inspect shows that the return value from update_job/2
includes "draft"
, but the two following inspects show that the job status is "published"
. This is causing my test to fail later on.
So can anyone think of why the return value shows one thing and following reads show something else? I’m quite stumped here.