Fix #2973: SortByColumns runtime error when called through UDF with missing columns#3060
Open
anderson-joyle wants to merge 2 commits intomainfrom
Open
Fix #2973: SortByColumns runtime error when called through UDF with missing columns#3060anderson-joyle wants to merge 2 commits intomainfrom
anderson-joyle wants to merge 2 commits intomainfrom
Conversation
…issing columns When SortByColumns is called through a UDF that accepts a typed table, the actual runtime table may omit columns that are optional in the UDF parameter type. The prior code validated sort column names against arg0.Type (the runtime table type), causing a false "column does not exist" error for any missing column. Fix: validate against irContext.ResultType (the compile-time return type), which equals the binder's argTypes[0] and includes all binder-validated columns. Missing fields are already returned as Blank by RecordValue.GetFieldAsync, so sort order is correct. Also bumps .Net7.0 test project TFMs to net8.0 (net7.0 EOL on this machine). Fixes #2973
Contributor
|
✅ No public API change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2973 —
SortByColumnsthrew"The specified column 'X' does not exist"at runtime when called through a UDF whose table argument omitted one of the declared sort columns.Root cause
SortByColumnsandSortByColumnsOrderTableinLibraryTable.csvalidated sort column names againstarg0.Type— the runtime table type. When a UDF is called with a narrower table (missing a column declared in the UDF parameter type),arg0.Typedoes not include that column, so the check incorrectly rejects it. The column was already validated at compile time.Fix
Changed
arg0.Type.FieldNames.Contains(columnName)to((TableType)irContext.ResultType).FieldNames.Contains(columnName)in both overloads.irContext.ResultTypeis the compile-time return type (equal toargTypes[0]) and includes all binder-validated columns.RecordValue.GetFieldAsyncalready returnsBlankfor missing fields.Files changed:
LibraryTable.cs— 2-line fix inSortByColumnsandSortByColumnsOrderTableRecalcEngineTests.cs—SortByColumns_UDF_MissingFieldregression test.Net7.0test project TFMs bumped tonet8.0(net7.0 EOL; may need reverting for CI)Confidence: 9 / 10
Full
Microsoft.PowerFx.Interpreter.Testssuite: 64,947 passed, 0 failed, 318 skipped. New regression test passed in isolation and withinRecalcEngineTests(227 tests). Minor gap: no dedicated test for theSortByColumnsOrderTableUDF-narrowed-table variant, though the full suite covers it implicitly.Test plan
SortByColumns_UDF_MissingFieldtest passesSortByColumns/SortByColumnsOrderTableexpression tests🤖 Generated with Claude Code