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

Magic Link login fails due to nil tenant for master user

Hi sorry, In my system, I have a master user whose site_id is nil. When I send a Magic Link request for this user, it successfully finds the user and returns a token. However, the issue occurs when I click on the link — one of the queries throws the following error: ```elixir [debug] QUERY ERROR source="users" db=0.4ms queue=0.3ms idle=750.5ms INSERT INTO "users" AS u0 ("id","site_id","confirmed_at","email") VALUES ($1,$2,$3,$4) ON CONFLICT ("email") DO UPDATE SET "email" = EXCLUDED."email", "confirmed_at" = EXCLUDED."confirmed_at" WHERE ((CASE WHEN u0."confirmed_at"::timestamp IS NULL THEN ash_raise_error($5::jsonb) ELSE $6 END)) RETURNING "site_id","confirmed_at","hashed_password","email","id" ["eebf4165-82d2-4c8b-9890-f11808d29c59", nil, ~U[2025-09-05 21:39:04.145886Z], #Ash.CiString<"master@example.com">, "{"input":{"resource":"Elixir.MishkaCms.Accounts.User","confirmation_strategy":"confirm_new_user"},"exception":"AshAuthentication.Errors.CannotConfirmUnconfirmedUser"}", true]...
Solution:
🥳

minor QOL improvement

I want to change this in the igniter task so it's navigate by default, this allows for spa like navigation (it's already used in the new chat link) https://github.com/ash-project/ash_ai/blob/41fd0ef906f9438b7b8a42f8ec4c840fcae82bf1/lib/mix/tasks/ash_ai.gen.chat.ex#L1118...

newb question: what's the actual use case of `ash_rate_limiter`?

Hello! Sorry, maybe I'm writing a dumb question, but here I go: isn't rate limiting a web concern, meaning something that belongs to the "plug and phoenix" layer? Therefore, what does ash have to do with it? Why wouldn't I just use hammer, plug it in, and call it a day?...

Reactor dynamic steps usage?

In the docs it is described steps can be dynamically created, but I see no docs on what it is expected to return. Here is the example from the docs: ```elixir...
Solution:
Here is an AI generated answer because I'm short on time. I've had really good luck with deepwiki, and reviewed what it said and it looks correct to me 🙂 https://deepwiki.com/search/in-the-docs-it-is-described-st_b46a5a96-c14f-46e2-81b2-2ad48f05f42d...

Sub domain multi tenancy - have magic links include sub domain

Hi everyone. I am using Ash attribuite based multi tenancy with sub domains. The issue I am having is that when the user receives a magic link, the magic link contains only my main domain not the subdomain the user originally used. So the user should receive something like org1.myapp.com/[rest of magic link] but they only receive myapp.com/[rest of magic link].. Is there a way I can modify the links that are sent out or how should I work around this? Thank you
Solution:
The tenant should be available as an option in the sender.

Calculation Heavy Resource with Historian Retrieval

Hello, was needing some help on a difficult problem. I have a calculation heavy resource (100+ calculations) that we would like to grab data out of our 3rd party historian sensor tables and perform calculations on as well as filter the results of certain calculations for metrics purposes. For example we would want to get the temperature over the course of a run and perform the average over the whole run. One caveat is that the sqlth_data tables are created weekly and have dynamic names for the tables that are stored in the partition tables and due to the historian data from tables require complex time-based filtering and dynamic table names its breaking my brain. I can make this work with calculate but i was hoping to make this work via expr is there something i am missing or could do that would help out my approach? ``` def expression(_opts, _context) do expr(...
No description

** (Mix) Could not invoke task "igniter.install": 1 error found!--auth-strategy : Unknown option

Got this error when running the HQ ash installer command that was auto generated based on the config I selected.
Solution:
Solved it using Visual Studio Build Tools:) Im using windows 11...

How to (temporarily) disable data layer entirely

I know this looks weird, but - given a starter project, I would love to properly configure AshPostgres, and then to "comment out" it and swap with an in-memory (non actually persistent) alternative, e.g. Ash.DataLayer.Ets (even better if any accidental entry gets deleted in 24hrs). Use case: I just want to start and deploy a simple static HTML page that requires no logic, nor authentication. In the near future, as I develop features, I want to put them back in. But in the meantime, I want to deploy my app without actually spending $38 per month for a postgres db I would not hit (yes, I'm using fly.io). If I'm tackling this problem wrong, or if you suggest a better workflow, I'm all ears!...
Solution:
But also if you're just not going to be using the resources at all, you can just not start your repo

Good way to (atomically?) persist a file when creating a record?

I'm working on a little project where one of the features is the ability to upload a file (using the :upload action which currently takes a :name and a :path as its arguments), which persists the file to disk and creates a File record in the DB. I want to do this in such a way that that I never end up with files on the disk that the DB doesn't know about, but also that no record is created if the file persistence has failed. How would I achieve this?...

Warning on compare to `nil` in short-circuited query

I have a query with an expression like this: ```elixir expr( is_nil(^start_date) or ^start_date <= fragment("date(?)", completed_date)...

Ash policies fail when they shouldn't

heres the logs ```elixir Parameters: %{"form" => %{"role" => "admin"}} [error] SimpleDemo.Accounts.User.change_role ...

Reducing some code duplication in Ash enums

I find myself defining a few enum modules in my application like this, ```elixir defmodule MyApp.MyDomain.SomeEnum do use Ash.Type.Enum, values: [:foo, :bar, :blah] ...
Solution:
I added some functions to Enum awhile back for this. Pretty sure there are some examples in the docs. https://hexdocs.pm/ash/Ash.Type.Enum.html#module-value-labels-and-descriptions...

How can I sum all the expenses.amount across all categories

I have a Category resource inside a Wallet domain. The Category has an attribute monthly_budget of type :money. Each category has many expenses, and each expense has an amount (also :money). On a domain level (in Wallet):...

Ash policies breakdown not showing help_text

I have this policy (check if the role theyre trying to change the user into is super_admin and if theyre not a super_admin themselves block them) ```policy action(:change_role) do forbid_if expr( args(:role) == :super_admin && ^actor(:role) != :super_admin...
Solution:
fixed

Distinguished if the user was created or if they already existed with a magic link

I would like to perform some actions once the user has been created via a Magic Link, for example sending a welcome email and initializing other resources in other domains. However, I don't see how to distinguish between creation and reading in an after_action. According to my tests, the values of the parameters are identical in both cases. Any ideas?...
Solution:
Here is what works for me: ``` upsert_fields [:email, :last_signed_in_at] ...

How to run custom resource extension before validators

Hi there, I'm writing my first Ash.Resource extension and having some issues I don't know how to solve. This is my simple extension so far: ```ex...
Solution:
You can do this in your transformer: ```elixir def before?(Ash.Resource.Transformers.DefaultAccept), do: true def before?(_), do: false...

Can I aggregate over a calculated field?

I have a File resource, that has calculation :extension, I then have another resource called Attachment, that has_many :files. Is it possible to do this: ``` first :extension, :file, :extension do...

Seed Resources with many-to-many relationships

Hello, I want to seed resources with many-to-many relationships. How would I accomplish this? I am thinking of doing something silly, just reference the rows that were inserted, considering that I don't know the actual IDs, and then read them appropriately and bulk-create them. Any ideas are welcome!...
Solution:
changeset generators. ended up doing what I said above, I basically created my own structs with the indices that I am interested in, and then just used Enum.at(foos, foo_index) to create the correct references. I also had to make the relationships on the many-to-many public so that I can create them. Anywho, thanks for the help!...

Regex validation error

Getting this error when validating:
validate match(:code, "^[A-Za-z0-9]+$/")
validate match(:code, "^[A-Za-z0-9]+$/")
```...

Generated attributes on update?

I've got a table using a generated value (GENERATED ALWAYS) which can change on updates. generated? true only appears to affect inserts. I'm guessing there is a toggle somewhere to handle this maybe? Even if there's just a way to tell an update action, "Hey, definitely get the return value on the update for this one," that would also be perfect. I didn't see any obvious way in the DSLs but... that doesn't mean much, lol....