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

Testing with AshAuthentication after upgrade

After upgrading ash_authentication_phoenix and ash_authentication to 2.10.0 and 2.9.2, this test helper function raises an error. ``elixir @doc """ Logs in a user with AshAuthentication` as the current user. """...
Solution:
🤔 You could generate a token and put it into __metadata__

Is there anyway to return a changeset from validation module?

I have a not-simple validation using pure Ecto in Phoenix project. And I want to port over to the project that is using Ash. With Ecto. we used to add errors to changeset in each function `def validate_something(changeset, some) do changeset...

Trickle down multitenancy :bypass

I have an entry point for a resource that bypasses the tenancy ``` read :get_public_event do get_by :id multitenancy :bypass...

Is there a way to detect running in "seed data" mode?

I added a custom GenServer that doesn't need to start when installing seed data using: mix run priv/repo/seeds.exs How might an Ash application know that it was invoked in a utility mode and not completely start itself?...
Solution:
Its not an Ash specific thing though

AshGraphql unknown error

``` Unknown Error * ** (UndefinedFunctionError) function :ok.resource/0 is undefined (module :ok is not available) :ok.resource()...
Solution:
You can create in a before_action hook and use that to update the record

Optimistic updates / syncing with AshEvents

hello! I am prototyping a new project using Ash, AshEvents, and AshStateMachine. It fulfills all of the requirements, save a big one: we need our application to support mutations when the client is offline, with eventual consistency. this leads to two problems: - is there any way to export / separately compile ash resource definitions in some way to be run on a client for optimistic edits, without duplicating the transitions / actions? - when a client returns online, is there a way to retroactively add events to the event log and then replay them? i.e. if an online client performs action A, then the offline client performs B, then the online client performs C, we'd like to generate the resource state in the order of A -> B -> C rather than A -> C -> B once the client syncs. It's not entirely clear from the documentation what happens during replay if the event log now contains events where applying them causes errors, such as illegal state transitions....

Ash Authentication `no case clause matching: "TOKEN_SIGNING_SECRET"`

When installing ash authentication hitting the following error:
mix igniter.install ash_authentication
mix igniter.install ash_authentication
``` Updating project's igniter dependency ✔ checking for igniter in project ✔...

Ash Oban trigger after action

@Rebecca Le continuing from ash oban channel; getting back to this, I have ``` update :my_action do set_attribute(:about_me, "Test")...

session_identifier compilation on AshAuthentication update

When updating AshAuthenticationPhoenix for the security advisory, I also updated AshAuthentication, and that also produces a compile-time error, which is not mentioned in the advisory. ``console ** (Spark.Error.DslError) authentication -> session_identifier: Must set authentication.session_identifier to either :jti or :unsafe`. ...
Solution:
the preferred solution would be to turn on require_token_presence_for_authentication? true

Custom payload body for post endpoint

How can create a generic action so that the exposed endpoint would accept the following payload: ``` { "event": "event", "data": {....}...
Solution:
But yeah TBH for webhooks I typically just write controllers

Error when using before_action hook to set required relationship attribute

I'm using a before action to lookup and set the :state_id by the state's name or code. However, the change doesn't seem to be running as I never see the Logger.debugs and I get changeset errors that :state_id is required. Have I misconfigured this hook?...
Solution:

`change manage_relationship(...type: :remove)` not working

I have a many_to_many relationship between Organization and SubscriptionPlan. The Organization has the following two actions: ```elixir update :subscribe do argument :plan, :struct, constraints: [instance_of: SubscriptionPlan]...
Solution:
So the mistake I was making was in my accessing_through policy: ```elixir policy accessing_from(MyApp.Accounts.Organization, :subscribers) do authorize_if always()...

ash_sqlite: Error when querying on an inline code calculation

Hey there! I'm trying out ash_sqlite on a toy project, and I'm encountering an issue which seems to boil down to querying a calculation defined as inline elixir code. Here is the error (full stacktrace in the next post), followed by some relevant code. Happy to add more context if required....
Solution:
You can't filter on calculations that don't define an expression

Counting Related Records with a Virtual Field in a Multi-Tenant app

In a multi-tenant application, when retrieving records from the database using a read action, is there a way to define a virtual field that counts the number of records in the database? For example, something like: ```elixir calculate ...

Error using AshArchival

I'm getting this error when attempting a read onto a ressource:
** (UndefinedFunctionError) function AshArchival.Resource.initial_state/4 is undefined or private
** (UndefinedFunctionError) function AshArchival.Resource.initial_state/4 is undefined or private
...
Solution:
Sorry actually ! I added it as an authorizer instead of an extension 😩 my bad for this...

Use arguments in Relationship

I would like to pass some arguments to a has_many relationship, which would be provided by a read action. `actions do read :list do argument :start_in, DateTimeUsec, allow_nil?: false...

Bind variables in queries

Had Gemini 2.5 Pro rewrite an adaptation of the ash_ai semantic_search usage rule example. ```elixir prepare before_action(fn query, context -> config = get_search_config(query.arguments) ...

`on_match: :error` should error on unique key violation?

Hi, I want to make an invitation accept action, invitation has a relationship member which is a belongs_to from Member, it has user_id, entity_id, which is a unique pair, I want to make accept create a :member relationship, so if a user accepts an invitation that is already in entity, it will throw unique identity violation This is what I have ```ex...

Thoughts on updating `ash_geo` to follow current ash extension patterns?

I'm considering using ash_geo, but noticed it doesn't use the same patterns extensions like ash_money for installing postgres extensions and types. I know it's not owned by the ash-project org, but wanted to see what people thing about giving it an overhaul to have a nicer installation experience and follow current extension patterns.

How do cleanly do action accepts for resources with a lot of attributes without `:*`?

With :* being deprecated in the future major version of Ash. Will you have to put all attributes in the accepts for the actions need to support all attributes? The answer very well may be you just have to list all the attributes in the action. But wanted to check....
Solution:
default_accept in the top level actions block