Ash Framework

AF

Ash Framework

The Elixir backend framework for unparalleled productivity. Declarative tools that let you stop wasting time. Use with Phoenix LiveView or build APIs in minutes for your front-end of choice.

Join

support

showcase

today-i-learned

ManualRead for wrapping an API using attribute constraints

I want to wrap an API with a resource. The response from the provider has a bunch of fields that can be "", which I'd prefer to be nil. Pretty sure this can be handled with constraints on attributes when the values are casted. The example in the docs shows manually creating the resource's struct from the API response and using Ash.Query.apply_to/2-3. Will this approach apply the constraints for the returned values doing this? Or is there a better way to make sure the constraints are applied?...
Solution:
I don't think it will cast those inputs, no

Is there a quick way to let Ash Authentication (Phoenix) inherit my custom daisyUI theme?

With Phoenix 1.18 (rc), daisy UI is now a thing. The thing I love about it is this theme builder, put into my css file, and tadah!, my app is fully customized. But ash_authentication ships with its own styles, which is fine on its own, but won't work well with phoenix from now on (imho). ...
Solution:
There is a PR up for this now ๐Ÿ™‚

Possible regression on actions with upserts on custom identity and embedded unions

Hi, I have a resource action that used to work until recently (on Ash 3.4.58), but now errors out (on Ash 3.5.21 and 3.5.23). Could this be a regression or did I miss something about it in patch notes? I'm not exactly sure how to proceed because it seems to be expecting an identity it really shouldn't be....
Solution:
@czen can you try main of ash?

datetime_add shows error Could not cast function arguments for datetime_add/3

calculate :ends_at, :datetime, expr(datetime_add(starts_at, minutes, :minutes))
calculate :ends_at, :datetime, expr(datetime_add(starts_at, minutes, :minutes))
I couldn't find any examples of datetime_add and assumed it should work in expr. ...
Solution:
:minute instead of :minutes

How to conditionally do `run_oban_trigger`?

I am modifing code from the Ash.AI chat example. I could understand that whenever a message is created, it goes through one of the change change run_oban_trigger(:respond) which triggers the trigger :respond. So, whenever user type a message and enter, an LLM response is generated. I want to change it to only user explicitly type like "@M, xxxx", then the response from LLM should be triggered. How to do that?...
Solution:
```elixir @impl true def change(changeset, _opts, _context) do case Ash.Changeset.get_attribute(changeset, :text) do nil ->...

How to setup "AshPostgres.Extensions.Vector"

I want to use Ash.AI to build RAG feature for my app. Currently, I am not sure how to setup AshPostgres for vector. According to the document: https://hexdocs.pm/ash_postgres/AshPostgres.Extensions.Vector.html An extension that adds support for the vector type....
Solution:
It goes in the lib/ folder, and in a .ex file

opentelemetry_ash not ready for use or not properly configured?

Hi! We're struggling with some performance issue in prod and can see some gaps between the top level spans (typically, LiveView event handlers) and DB queries. So there's a suspicion that something might be going slow in building queries and/or processing results. So we've tried enabling opentelemetry with the opentelemetry_ash package (0.1.0). But it doesn't seem to hook correctly into the parent spans, looks kind of useless and hard to navigate. We use SigNoz to visualise the spans, it looks like on the screenshot....
No description

Creating a resource from another endpoint

Hey everyone! Iโ€™m running into a bit of a challenge and could use your input. I have an endpoint called locations, and I want to allow users to create leads as part of a POST request to: {{url}}/api/json/location...

Precondition checks and atomic

I often have to check the current value of a resource object in the DB as part of precondition checks of an action (e.g. when updating a "status" column I have to make sure it has a specific value before doing it). At first I tried to use "validation" for this but that seems to be only for input arguments and input attributes. So instead I used "change before_action" hooks to load the existing record and add an error to the Changeset if needed....

Is there a way to trigger a before_action without trying to run it?

I am doing some bulk-prevalidation where I am just doing an Ash.Changeset.for_create(..) to run validations. I need to load some related records based on a foregin key id in the inputs. Essentially I am validating if an architectural_element is valid, but it needs to use the study_id to load a study and all its related Outcrop so see that the chosen geology type exists in any of the related Outcrop. In a regular create I would just do a before action and look it up and then add error as needed. ...

Port conflict when running new app built using Ash installer

I used the Ash installer to generate a new app: ``` mix archive.install hex igniter_new --force mix archive.install hex phx_new 1.8.0-rc.3 --force...

ash ai chat

``` [error] ** (NimbleOptions.ValidationError) unknown options [:unsafe_], valid options are: [:hardbreaks, :github_pre_lang, :full_info_string, :width, :unsafe, :escape, :list_style, :sourcepos, :escaped_char_spans, :ignore_setext, :ignore_empty_links, :gfm_quirks, :prefer_fenced, :figure_with_caption, :tasklist_classes, :ol_width, :experimental_minimize_commonmark] (in options [:render]) (nimble_options 1.1.1) lib/nimble_options.ex:359: NimbleOptions.validate!/2 (mdex 0.7.1) lib/mdex.ex:1376: MDEx.validate_options!/1 (mdex 0.7.1) lib/mdex.ex:951: MDEx.to_html/2...

Cinder.Table count timeout not working as expected

Hey @sevenseacat i saw that there was a new version with fixes for the timeout and this issue was closed (https://github.com/sevenseacat/cinder/issues/7) But i'm still getting the same error even when setting the query_opts={[timeout: :timer.seconds(20)]} ```elixir 11:52:17.499 [error] Task #PID<0.16899.0> started from #PID<0.16897.0> terminating...
Solution:
I can fix that

Auto generated `reset_password_with_token` not loading user

Hi everyone! ๐Ÿ‘‹ Iโ€™m trying to expose the auto-generated reset_password_with_token action via Ash GraphQL, but I keep getting a not_found error no matter what I try. Hereโ€™s my setup (auto generated): ```...
Solution:
seems like: ``` bypass action(:read) do authorize_if expr(id == ^actor(:id)) end...

Is there a way to overwrite `:langchain` to specify to use custom forked version?

I found Ash.AI is really cool. However, I need to interact with other LLM provider that doesn't supported by {:langchain, "~> 0.3"}. So, I need to fork the langchain and plan to write modules for that provider. When I specifiy my forked repo in phoenix's mix.exs, it failed at setep: mix deps.get with error: Because every version of ash_ai depends on langchain ~> 0.3 which doesn't match any versions, no version of ash_ai is allowed....
Solution:
Use `override: true' in your custom langchain dependency

Problems with AshRateLimiter

After spamming in the general channel I was redirected here ๐Ÿ˜… I'm trying to setup AshRateLimiter but it crashes when I test a rate limited action giving me undefined Hammer.hit function. I thought AshRateLimiter would pull in the Hammer lib? I installed it and configured it manually and it works The problem I then got is that now it's warning: reset_password_with_token cannot be done atomically, because the changes [AshRateLimiter.Change] cannot be done atomically But I'm not rate limiting that action, it shouldn't be affected (I think?)...

Managing many_to_many relationships with AshPhoenix.Form

Hi all, I'm really struggling to get AshPhoenix.Form to manage a many to many relationship. I have 2 resources, Organizations and Users. I have a many_to_many relationship between them. What I'm trying to achieve, is that when I create/edit an organization, there should be a multi select to be able to select related users. ``` create :create do...
Solution:
Like fetching the possible users and assigning them on mount

destroy + create behavior on has_one relationship

is there a way to have manage_relationship with: - destroy the previous has_one - create a new one from what i understand, it's not quite append_and_remove, because it requires an update to the target record....

How to create a Union query within different resources with Combination

Looks like the api to perform a Union query is https://hexdocs.pm/ash/combination-queries.html but what would be the best way to create a union query between different resources?

Ash Framework Book: Missing filepath's for code changes in Chapter 7

Are we supposed to implement these changes? Im on version B6.0 of the book using epub
No description