Framework Error - Assumption failed: Invalid return from calculation
Hi,
I’m encountering a Framework Error with the message:
Assumption failed: Invalid return from calculation, expected a value, got %Ash.NotLoaded{}
The full error trace is attached below. I'm unsure whether this is caused by a mistake on my side or if it's a potential bug in the framework.
If you need any additional details (resource definitions, calculations, test cases, etc.), I’m happy to provide them.
Thanks in advance!9 Replies
A reproduction would be great
It's a bit messy. I see what I can do to make it minimal 😅
This test reproduces the error. It's still a lot of stuff going on. Let me know when you have any questions.
You were missing load statements in your changes
the load callback is for also for attributes, because they can als be %Ash.NotLoaded{} when they are not selected, so you need to make sure to have them in calc load statements as well. Not just other calculations and relationships and so on
so it's not recursively resolving the dependencies of the loaded calculations?
It does, but the nested calculations didn't have the necessary fields in the loads.
_building_type
was not specified in any of the calculationsOh now I get it, so the calculations even have to explicitly load the fields on the resource they are attached to, not only the fields from relations. I added all of them and now it works! Thank you very much for the help! 🙇♂️
yeah, exactly. This might have been more explicit in Ash 2.0 https://hexdocs.pm/ash/upgrading-to-3-0.html#calculations-do-not-have-a-select-3-callback-any-more
It's mentioned here in the comment for the load statement https://hexdocs.pm/ash/calculations.html#module-calculations but we could probably make it a bit more visible
I read through that code comment but because it only mentions:
posts: [:title, :body]
.
I thought it applies only to loading relationship fields. But now that I think about it again, it makes much more sense that you have to explicitly load everything in a calculation, even fields on the same resource.