Fix InvalidLoad for struct calculations without arguments#53
Fix InvalidLoad for struct calculations without arguments#53cinoss wants to merge 3 commits intoash-project:mainfrom
Conversation
Struct calculations (`:calculation_complex`) without arguments fail with
`Ash.Error.Query.InvalidLoad` when requested via RPC. The field selector
builds a nested load spec like `{:calc_name, [:field1, :field2]}`, but
Ash only supports nested loads on relationships — not on calculations.
This changes `:calculation_complex` handling in two places:
1. `process_nested_resource_field`: load the calculation flat (just the
atom name) instead of building nested load specs. The extraction
template still tracks sub-fields for response formatting. This
matches how aggregates are already handled.
2. `process_simple_resource_field`: allow `:calculation_complex` as a
simple field request, loading it flat and returning all sub-fields.
Calculations with arguments (`:calculation_with_args`) are unaffected —
they go through `process_calculation_with_args` which correctly passes
args via `{:calc_name, {args, fields}}`.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Tests now assert success instead of failure for :calculation_complex fields without arguments, matching the fix in field_selector.ex that loads these calculations flat and delegates sub-field extraction to the response template. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| {select, load ++ [load_spec], template ++ [{internal_name, nested_template}]} | ||
|
|
||
| :calculation_complex -> | ||
| # Ash doesn't support nested loads on calculations (only on relationships). |
There was a problem hiding this comment.
Ash does support that, it just needs to be specified as calculation: {[arg: :val], [load: :through]}
There was a problem hiding this comment.
@zachdaniel I have made some change, can you plz have a look?
…ources, bare atom for TypedStruct Ash's load_through only works for calculations returning Ash Resources (which support queries). TypedStruct/typed map calculations must load as bare atoms — sub-field extraction is handled by the extraction template. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Sorry for taking so long to jump on this one 😅 I have now fixed this issue in Please note that for all complex fields that are in some way typed, ash_typescript always requires the caller to specify which fields they want back, so requesting a complex field just by its field name still won't work. Hoping to put out a new release before the week is done with this fix and some other updates 😄 |
Summary
Fixes an issue where struct/embedded resource calculations without arguments couldn't be requested via RPC — neither as simple fields nor with field selection.
The
field_selector.exclassified these as:calculation_complexand:"summary") → rejected withrequires_field_selection{summary: ["viewCount"]}) → built a nested load spec{:summary, [:view_count]}that Ash doesn't support for calculations, causingInvalidLoadCalculations with arguments worked fine because they go through
:calculation_with_args, a different code path.Fix
For
:calculation_complexwithout arguments:Changes
lib/ash_typescript/rpc/field_processing/field_selector.ex— Handle:calculation_complexin bothprocess_simple_resource_fieldandprocess_nested_resource_fieldTest plan
["summary"]→ loads flat, returns all sub-fields{summary: ["viewCount"]}→ loads flat, template extracts sub-fields{summary: [{performanceMetrics: ["focusTimeSeconds"]}]}🤖 Generated with Claude Code