An aggregate field loaded in create action isn't available for pub_sub?
publish :create, ["update", :aggregate_field1]
in one of my resources fails with the following error, despite the fact that change load(:aggregate_field1)
is in the action definition. If I remove the publish
setting from pub_sub, the create action succeeds, with the :aggregate_field1 properly loaded to the changeset.
I wonder if something changed about how pub_sub works in Ash lately, because my pub_sub and create action codes used to work fine. I did recently update ash to the latest version. Thanks.42 Replies
@Zach Daniel can you please give me some pointers as to how to troubleshoot this?
So, aggregates are not automatically loaded by the publishing logic
I think that’s something we could actually improve, but until then in order to use them like that you have to make sure they are always loaded. And actually yeah I just realized what broke them 🤔
Are you using
change load
to load required data for your notifiers?yes
yeah, okay, I broke this functionality, my apologies
Can you open an issue on
ash
core and I'll fix it ASAP?Sure. Thanks!!
GitHub
Aggregates loaded in the action is not available for publishing · I...
Describe the bug A clear and concise description of what the bug is. aggregates loaded via change load[:aggregate_field] is showing up as nil when publish :create, ["update_signup", :aggr...
Hey, so actually looking at the code I think this actually ought to work? Or maybe I don't understand the issue as well as I thought I did.
what type of action are you noticing this for?
nvm I can see from your example its a create action
and you have
change load(:aggregate_field1)
in the :create
action?yes, that's right.
are you on the latest version of ash?
I saw you upgraded recently
but how recently 😆
we move quick
As you know
2.9.25
If I comment out the
publish :create ...
line, the action successfully completes, with the aggregate loaded to changeset properlyokay, interesting 🤔
That makes me feel comfortable about the other part of the code.
Yeah, so it should be pretty isolated to the creation of notifications
ah, okay I found it 😄
can you try
main
to confirm the fix?Sure. one sec
Hmm... still getting the same error. Interestingly, the aggregate field isn't loaded at all, even with
publish ...
commented out.
Almost as if change load[...
is ignored.hrm...
something there is very strange
are you sure you're doing things the same? Or that the
main
that you're using is latest? Basically all I changed was one line:
{:ok, result, Map.put(instructions, :notification_data, result)}I didn't change the return value, so the aggregate should definitely still be loaded if it was before...
mix deps
shows ash 2.10, so that's goodyour mix.exs points at the github tho right?
no... I saw 2.10 was the same as main. 😦
let me try github
*I thought 2.10 was the same
yeah, new commits are on the main branch in GH 🙂
although still concerning if 2.10 it wasn't even loading at all
but lets just see what happens on the GH version, if it all works then it can just be released and we can move on 😆
unfortunately, no change from my earlier attempt.
same error. and the aggregate is not loaded to the changeset.
fyi. I have this at the bottom of the create action to see what the changeset looks like.
ah 🙂
when you say its not loaded into the changeset WDYM?
what do you see inspected on the changeset?
sheet_id: #Ash.NotLoaded<:aggregate>,
yeah, that makes sense though
if its in the
data
key of the changeset
thats the before
Its actually not possible to, within the action, inspect something that has been loaded by change load
because we do it after all the action steps are doneI see.
so you'd need to run the create yourself and inspect it
Either way, I think what this means is just that I haven't fixed the original bug
I will try to look at the pub sub notification code to see if I can figure it out as well.
I wouldn't worry about it 🙂
Its deeper than that, unfortunately
I'll have it fixed shortly, just got it reproduced in a test
nice !!
okay, main is ready to try again 🙂
Got it
It's working! Thank you!
@Zach Daniel Same situation but this time the update action is using
manual
. and change load([:sheet_id])
where :sheet_id is coming from a belongs_to relationship, seems to be ignored, and I'm getting this error again. Does that make sense?
does this happen on the latest published ash rc version?
let me try.
Yes, rc.2 produces the same result.
what if you do
change select(:sheet_id)
?let me try
same issue
can you try
main
?
I've just pushed some stuff upsure
sorry, no luck
I see where you made changes, I will try to do some debugging on my end as well.
Try main now 🙂
We had some other bugs along a similar vein
okay!
Sorry, still the same error.
using
* ash 2.11.0-rc.3 ([email protected]:ash-project/ash.git) (mix)
locked at db375ef
🤔 🤔 🤔
do you have this replicated when its not a manual action?
This doesn't happen if it's not a manual action.
Okay, thanks. I’ve been a bit strapped for time lately. If you have a chance to reproduce this behavior in a test in Ash that would be very helpful
Sure. will try.