Route Parameter Variable Ordering in Marten Batch Queries #2017
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.
This PR fixes a code generation bug where route parameters were used before they were declared when combining
[WriteAggregate]/[ReadAggregate]attributes with Load/Before midleware methods.The fix ensures
MartenBatchFrameproperly declares its dependencies on variables used by batchable frames, allowing the code generation topological sort to order frames correctly.Issue
When an endpoint combined:
Load(Guid id)orBefore(Guid id)[WriteAggregate]or similar attributeThe generated code would fail with
CS0841: Cannot use local variable 'id' before it is declaredbecause:idMartenBatchFramedidn't declare its dependencies on route parametersRoot Cause
The
MartenBatchFrame.FindVariables()method only yieldedIDocumentSessionandCancellationToken, but not the variables that its batchable frames (likeLoadAggregateFrame) needed.Solution
Adjusted
MartenBatchFrame.FindVariables()to also enumerate and yield all variables that its enlisted batchable frames depend on.Test Results
reacting_to_read_aggregate was modified to add Load and Before., this cuased 3 tests to fail. Adding the fix makes them pass, and not additional tests to fail.
Generated Code Verification
The generated code now correctly declares the route parameter before using it in the batch query: