scope/context is not passed to ManualRead action

Hi, just wanted to ask if this is intentional and if so, where I can find more information. I have a very simple scope like
scope = %MyApp.Scope{
vertical: :foo
}
scope = %MyApp.Scope{
vertical: :foo
}
And then there's a manual read action for an external API that looks like
actions do
read :read do
primary? true

manual fn query, _, _opts, context ->
# Does remote api call here
end
end
end
actions do
read :read do
primary? true

manual fn query, _, _opts, context ->
# Does remote api call here
end
end
end
On the domain there's
define :get_by_slug, action: :read, get_by: [:slug]
define :get_by_slug, action: :read, get_by: [:slug]
Then in tests I have the scope like above and call
{:ok, value} = MyApp.MyDomain.get_by_slug("some_slug", scope: scope)
{:ok, value} = MyApp.MyDomain.get_by_slug("some_slug", scope: scope)
I expect the "vertical" key to show up in the context of the ManualRead action but it doesn't. I'm doing the same with generic actions elsewhere and there it shows up as "context.source_context.vertical". Am I holding it wrong? Is the difference between manual actions and generic actions intentional?
4 Replies
ZachDaniel
ZachDaniel3w ago
There are two contexts the context of the callback, and the context of the query you're saying its not showing up under context.source_context?
Felix
FelixOP3w ago
Ok, I dug through the source and I've found it under "query.context" (first argument of the callback) instead of "context" (last argument). I didn't find it earlier because using dbg() on the query doesn't show that there's even a "context" in there. I still don't think I have any intuition which context is used for what but at least I know where to look for now. Thank you for the quick help as always, it means more than you think! ❤️ Would adding "context" to the Inspect impl of Ash.Query be something I could do as a PR?
ZachDaniel
ZachDaniel3w ago
We intentionally hide it at the moment because it can have all kinds of information in it TBH would have to think about it
Felix
FelixOP2w ago
For reference, I put up a proposal (and initial PR): https://github.com/ash-project/ash/pull/2441
GitHub
improvement: include context in inspect consistently by felixbr · ...
Contributor checklist Leave anything that you believe does not apply unchecked. I accept the AI Policy, or AI was not used in the creation of this PR. Bug fixes include regression tests Chores ...

Did you find this page helpful?