vkryukov

vkryukov

Hi, I have the following calculation in one of my resources:

  calculations do
    calculate :llm_model,
              :map,
              expr(
                cond do
                  role == :basic -> %{"model" => "gpt-4o-mini"}
                  role == :pro -> %{"model" => "o3-mini", "reasoning_effort" => "medium"}
                  role == :admin -> %{"model" => "o3-mini", "reasoning_effort" => "high"}
                end
              )
  end

This compiles without any problems, and my reading of Ash.Resource — ash v3.29.3 is that any return type, including :map, is allowed.

However, I get the following error when executing this code, where victor is a User resource:

victor |> Ash.load!(:llm_model)
[debug] QUERY ERROR source="users" db=2.3ms queue=1.4ms idle=1593.8ms
SELECT u0."id", (CASE WHEN u0."role"::varchar::varchar = $1::varchar::varchar THEN $2 WHEN u0."role"::varchar::varchar = $3::varchar::varchar THEN $4 WHEN u0."role"::varchar::varchar = $5::varchar::varchar THEN $6 ELSE NULL END) FROM "users" AS u0 WHERE (u0."id"::uuid::uuid = $7::uuid::uuid) [:basic, %{"model" => "gpt-4o-mini"}, :pro, %{"model" => "o3-mini", "reasoning_effort" => "medium"}, :admin, %{"model" => "o3-mini", "reasoning_effort" => "high"}, "ab2ba555-671f-4d73-861d-c9171ec7ec9b"]
↳ anonymous fn/3 in AshPostgres.DataLayer.run_query/2, at: lib/data_layer.ex:785
** (Ash.Error.Unknown)
Bread Crumbs:
  > Error returned from: FiveWhys.Accounts.User.read

Unknown Error

* ** (DBConnection.EncodeError) Postgrex expected a binary, got %{"model" => "gpt-4o-mini"}. Please make sure the value you are passing matches the definition in your table or in your query or convert the value accordingly.
<...>

I understand it that there is an attempt to evaluate the expression in Postgresql level, which understandably fails.

Am I expecting too much from calculated fields here? I can of course split it into two calculated fields, e.g., model and reasoning_effort, but I’m curious what is the idiomatic Ash solution here.

Showing Posts 1 to 3

zachdaniel

zachdaniel

Creator of Ash

This is a bug. Can you open an issue on the ash_postgres repo with a link to a reproduction?

zachdaniel

zachdaniel

Creator of Ash

And make sure that you’re on the latest versions of everything and that its still not working :smile:

vkryukov

vkryukov OP

Yes, upgraded everything and can confirm that the bug is still there:

Upgraded:
  ash 3.5.2 => 3.5.4
  ash_admin 0.13.3 => 0.13.4
  ash_authentication 4.6.3 => 4.6.4
  ash_authentication_phoenix 2.5.2 => 2.5.3
  ash_graphql 1.7.6 => 1.7.7
  ash_phoenix 2.1.25 => 2.1.26
  ash_postgres 2.5.14 => 2.5.15
  ash_sql 0.2.66 => 0.2.67

Created a ticket: Calculated field with :map return type doesn't work with Postgres backend · Issue #528 · ash-project/ash_postgres · GitHub

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews