improvement: Add prepend? opt to hooks and Ash.Subject transaction hooks#2221
Conversation
- Adds `prepend?` opt for all hooks except for `Ash.Query.after_action` since it uses `@read_action_after_action_hooks_in_order?`
- Clean up type specs - Add before/after,around transaction hooks to Ash.Subject
|
I removed the default implementations and delegate to the subject type modules. |
64e3a56 to
4ae7544
Compare
- Update all functions to delegate to the subject type module function - Align type specs with subject type module types - Update `get_argument/3` to only return the default value when `:error` is returned from `fetch_argument/2` - Add `Ash.ActionInput.delete_argument/3` - Add `Ash.Changeset.fetch_attribute/2` - Add `Ash.Changeset.fetch_data/2` - Add `Ash.Changeset.fetch_argument_or_attribute/2` - Update `Ash.Query.fetch_argument/2` to first call `Ash.Query.new(query)` like other functions to ensure the subject is a query. - Remove `set_private_argument/3` tests because there is a bug where `new/1` doesn't add the `arguments`, but `set_argument/3` is using dot syntax to access the arguments. So, there's no way to use `set_private_argument/3` without getting the warning message. I'll submit another PR to fix this" -
4ae7544 to
08bf489
Compare
|
Ok, It should be good to go now. Let me know if you need anymore changes. Few items for future PRs:
|
|
@zachdaniel Thanks for the time and patience reviewing the PRs. I've been off work this week and wanted to contribute a bit. |
For this one, I think it will be better to leave them in their respective places. We'll never have another subject type, and it is possible their implementations will intentionally drift. Having the unified |
|
🚀 Thank you for your contribution! 🚀 One small note: we want to be careful to avoid scope creep on individual PRs since it can make it a bit tougher to review.
Not at all! these are great changes, so thank you! |
Fair enough. For the scope creep, I definitely realized this one was getting a pretty big. I'll keep them smaller in the future to reduce the risk of y'all missing something. |
Changes
prepend?option to Changeset, ActionInput, and Query hooks. Except forAsh.Query.after_actionwhich uses@read_action_after_action_hooks_in_order?Ash.Subjectsince Changeset, ActionInput, and Query now all support them.get_argument/3to only return the default value when:erroris returned fromfetch_argument/2Ash.ActionInput.delete_argument/3Ash.Changeset.fetch_attribute/2Ash.Changeset.fetch_data/2Ash.Changeset.fetch_argument_or_attribute/2Ash.Query.fetch_argument/2to first callAsh.Query.new(query)like other functions to ensure the subject is a query.set_private_argument/3tests because there is a bug wherenew/1doesn't add thearguments, butset_argument/3is using dot syntax to access the arguments. So, there's no way to useset_private_argument/3without getting the warning message. I'll submit another PR to fix this"Contributor checklist
Leave anything that you believe does not apply unchecked.