ash-project / ash-project/ash

Can no longer call `typed_struct` multiple times

Open
#2,295 5 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

### Code of Conduct

- [x] I agree to follow this project's Code of Conduct

### AI Policy

- [x] I agree to follow this project's AI Policy, or I agree that AI was not used while creating this issue.

### Versions

Broke in version [v3.5.35](https://github.com/ash-project/ash/releases/tag/v3.5.35) due to this commit https://github.com/ash-project/ash/commit/0fb406aecde970ad8e6252fb82b672ab1bf6f714

### Operating system

OSX

### Current Behavior

We recently tried upgrading to v3.5.36 from v3.5.34. Once we did we got a new error

```
(ArgumentError) defstruct has already been called for EKG.Scenes.Events.ChannelFollowed, defstruct can only be called once per module
```

This module does the following:

```ex
defmodule EKG.Scenes.Events.ChannelFollowed do
use EKG.Scenes.BaseEvent

typed_struct do
field :follower_id, :string, allow_nil?: false
# ... etc ...
end
end
```

Where `EKG.Scenes.BaseEvent` is

```ex
defmodule EKG.Scenes.BaseEvent do
defmacro __using__(_opts) do
quote do
typed_struct do
field :platform, :atom, allow_nil?: false, constraints: [one_of: [:twitch, :youtube]]
# The "raw" event from original source
field :raw, :map, allow_nil?: false
end
end
end
end
```

This idea being that the base event ensured all events had those two fields.

### Reproduction

```ex
defmodule Test do
typed_struct do
field :foo, :string
end
typed_struct do
field :bar, :string
end
end

### Expected Behavior

Expect the two `typed_struct` calls to be merged as they used to be. OR a user story of how to accomplish what we were doing before

Contributor guide

Open the contributing guide

Research direction

Start by reading the regression commit linked in the issue and tracing the `typed_struct` calls in `Test`, `EKG.Scenes.BaseEvent`, and `EKG.Scenes.Events.ChannelFollowed`. Reproduce the `defstruct has already been called` error, then verify either that multiple calls merge again or that the supported replacement for the base-event pattern is documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.