has_create_action?/1 excludes manual creates, making the #49 nullability fix inert on AshEvents resources
Maintainers usually reply within 1 day
@Mckay-Hinds is already working on this.
Since Oct 28, 2026.
- #913 by @hoanle0126 — closed without merging
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 76/100
Research direction
Start in migration_generator.ex at has_create_action?/1 and follow its count into merge_attributes/3. Reproduce the shared-table case with AshEvents-wrapped create actions; done when manual creates are counted and subtype-specific columns generate as nullable, preserving the behavior described for non-evented resources.
Written by the indexing model from the issue text.
Description
Version
ash_postgres 2.13.0, ash 3.32.3, ash_events in use on the affected resources.
Summary
has_create_action?/1 excludes actions that declare manual. AshEvents implements its audited actions as manual actions, so on any resource with an event log has_create_action? returns false even when the resource has ordinary create actions.
The consequence is that the fix for #49 — "required attributes that aren't on all resources using that table should not be marked as null: false" — is silently inert whenever the resources sharing a table are evented.
The chain
migration_generator.ex:
defp has_create_action?(resource) do
resource
|> Ash.Resource.Info.actions()
|> Enum.any?(&(&1.type == :create && !&1.manual))
end
feeds the per-table count:
count_with_create =
snapshots
|> Enum.count(& &1.has_create_action)
which is the count in merge_attributes/3:
allow_nil?: Enum.any?(attributes, & &1.allow_nil?) || Enum.count(attributes) < count,
That second clause is #49's fix. When every resource on the table is evented, count is 0, so the clause is n < 0 and never fires.
Why manual is set
An AshEvents-wrapped create reports:
manual: {AshEvents.CreateActionWrapper, [action: :identify, event_log: MyApp.EventLog, version: 1, ...]}
so !&1.manual is false.
Reproduction
Two resources sharing one table, in the shape used for single-table inheritance — a supertype with no create actions, and subtypes each with a base_filter and their own columns:
# table "notes", resources: Note (supertype), TextNote, FlagNote
defmodule MyApp.TextNote do
use Ash.Resource,
domain: MyApp.Domain,
data_layer: AshPostgres.DataLayer,
extensions: [AshEvents.Events] # <- remove this and the bug disappears
postgres do
table "notes"
repo MyApp.Repo
base_filter_sql "kind = 'text'"
end
resource do
base_filter expr(kind == :text)
end
events do
event_log MyApp.EventLog
end
actions do
defaults [:read]
create :write do
accept [:body]
end
end
attributes do
attribute :kind, :atom, allow_nil?: false, writable?: false, default: :text
attribute :body, :string, allow_nil?: false # declared only by this subtype
end
end
FlagNote is the same shape with kind = 'flag' and its own :reason column.
Expected: body and reason are generated nullable — neither is declared by every creating resource on the table, which is exactly what #49 asks for.
Actual: both are generated null: false, so a row of either kind is impossible to insert:
alter table(:notes) do
add :body, :text, null: false
add :reason, :text, null: false
end
Removing extensions: [AshEvents.Events] from the subtypes makes has_create_action? return true and the columns generate nullable as expected.
Observed in a real app
Across one codebase, with has_create_action? evaluated per resource:
Commitment evented=false creates=0 -> has_create_action=false
Appointment evented=false creates=1 -> has_create_action=true
Job evented=true creates=2 -> has_create_action=false
Job has two ordinary create actions and reports false solely because they are wrapped.
Suggested fix
The predicate is about "does anything insert rows into this table", and a manual create does insert rows. Counting manual creates — Enum.any?(&(&1.type == :create)) — would restore #49's behaviour for evented resources. If manual actions are excluded deliberately for some other reason, it may be worth naming that reason in a comment, since the interaction with ash_events is invisible at the call site.
Workaround
Declare the kind-specific column allow_nil? true and enforce presence with a validation plus a check constraint. That works, but it means the resource no longer states its own rule.
- Dominant language
- Elixir
- Stars
- 191
- Forks
- 186
- Avg merge
- 16h 4m
- Merged PRs (30d)
- 17
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ash-project/ash_postgres
-
Temporal: an update or destroy as of an instant doesn't carry into later versionsPossibly taken @hoanle0126 claimed this 13 days ago. Open
Difficulty 5/5 Over a week Newbie friendliness 15/100
ash-project/ash_postgres#915 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ash-project/ash_postgres#650 · 6 comments ·
Maintainers usually reply within 1 day
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 35/100
ash-project/ash_postgres#642 · 5 comments ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 40/100
ash-project/ash_postgres#628 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement good first issue
Difficulty 4/5 3-5 days Newbie friendliness 48/100
ash-project/ash_postgres#538 · 1 comment ·
Maintainers usually reply within 1 day
All issues in ash-project/ash_postgres
Similar issues
-
@swmansion/popcorn: published .d.ts files lack extensions on relative imports, breaking moduleResolution node16/nodenextPossibly taken @Huyvux12 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
software-mansion/popcorn#929 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
ash-project/ash#3127 ·
Maintainers usually reply within 1 day
-
Bug: Table layout and date column are cut off on mobile screens on the Tournaments -> History pageOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
hexlet-codebattle/codebattle#2375 ·
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
wintermeyer/vutuv#2388 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100