ash-project / ash-project/ash

Ash Custom Types Constraints Validations

Open
#1,899 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Elixir
Stars
2.5k
Forks
422
Avg merge
23h 26m
Merged PRs (30d)
46

Description

**Describe the bug**
There are no compiler errors to misconfiguring the constraints fields keyword lists.

**To Reproduce**
Create a new type with an incorrect type keyword list.

```elixir
defmodule MyApp.FooType do
alias MyApp.BarResource
use Ash.Type.NewType,
subtype_of: :map,
constraints: [
fields: [
bars: [type: :struct, instance_of: BarResource]
]
]
end
```

The correct keyword list would be as such:

```elixir
defmodule MyApp.FooType do
alias MyApp.BarResource
use Ash.Type.NewType,
subtype_of: :map,
constraints: [
fields: [
bars: [type: :struct, constraints: [ instance_of: BarResource]]
]
]
end
```

**Expected behavior**
An error at compile time for unknown keys or incorrect keys.

**Runtime**
- Elixir version 1.18.1
- Erlang version 27.2
- OS macOS Sonoma 14.7
- Ash version 3.4.71
- any related extension versions
- ash_json_api 1.4.22

**Additional context**

Link to discord thread: https://discord.com/channels/711271361523351632/1254774851428814930/1352834543408775228

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the MyApp.FooType example using Ash.Type.NewType and its constraints fields keyword list. Trace where the custom type constraints are processed and check existing validation tests, if present. Done means the incorrect top-level keyword list produces a compile-time error for unknown or misplaced keys.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
developer-experience
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.