close
Skip to content

.NET: fix: preserve Foreach record values - #6208

Merged
Tao Chen (TaoChenOSU) merged 1 commit into
microsoft:mainfrom
he-yufeng:fix/foreach-preserve-record-values
Jun 5, 2026
Merged

.NET: fix: preserve Foreach record values#6208
Tao Chen (TaoChenOSU) merged 1 commit into
microsoft:mainfrom
he-yufeng:fix/foreach-preserve-record-values

Conversation

@he-yufeng

Copy link
Copy Markdown
Contributor

Fixes #6183.

Summary

  • preserve each RecordDataValue as a full record when Foreach materializes table rows
  • add a regression test for a multi-field row so the loop value exposes both fields

To verify

  • dotnet test --project tests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests.csproj -f net10.0 -v Normal --filter-class Microsoft.Agents.AI.Workflows.Declarative.UnitTests.ObjectModel.ForeachExecutorTest
  • dotnet test --project tests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests.csproj -f net472 -v Normal --filter-class Microsoft.Agents.AI.Workflows.Declarative.UnitTests.ObjectModel.ForeachExecutorTest
  • dotnet format agent-framework-dotnet.slnx --verify-no-changes --no-restore --include src\Microsoft.Agents.AI.Workflows.Declarative\ObjectModel\ForeachExecutor.cs tests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests\ObjectModel\ForeachExecutorTest.cs
  • git diff --check

Copilot AI review requested due to automatic review settings May 30, 2026 14:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Fixes a bug in ForeachExecutor where iterating over a TableDataValue only exposed the first field of each record instead of the full record.

Changes:

  • Replace value.Properties.Values.First().ToFormula() with value.ToFormula() so the full record is yielded per iteration.
  • Add a unit test verifying multi-field records expose all fields via the loop variable.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/ObjectModel/ForeachExecutor.cs Yield full record (not just first property) when iterating a table.
dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/ObjectModel/ForeachExecutorTest.cs Adds test asserting all record fields are accessible from the iteration variable.

@moonbox3 Evan Mattson (moonbox3) added .NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows labels May 30, 2026
@he-yufeng

Copy link
Copy Markdown
Contributor Author

Rebased on current upstream/main and reran the scoped Foreach validation locally.

Validated:

dotnet build .\tests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests.csproj -f net10.0 -c Debug --tl:off
dotnet test --project .\tests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests\Microsoft.Agents.AI.Workflows.Declarative.UnitTests.csproj -f net10.0 -c Debug --no-build -v Normal --report-xunit-trx --ignore-exit-code 8 -- --filter-class Microsoft.Agents.AI.Workflows.Declarative.UnitTests.ObjectModel.ForeachExecutorTest
git diff --check upstream/main...HEAD

All passed after the rebase.

@peibekwe

Copy link
Copy Markdown
Contributor

Thanks for the fix Yufeng He (@he-yufeng)! I'm going to land this, then layer a single-column unwrap on top to preserve =[...] literal back-compat, separate PR coming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET Usage: [Issues, PRs], Target: .Net workflows Usage: [Issues, PRs], Target: Workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: Declarative Foreach collapses multi-field records to their first field in the loop value variable

5 participants