question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ItemRequestOptions not flowing to custom RequestHandler RequestMessage when AllowBulkExecution is set to true

See original GitHub issue

We are continuously addressing and improving the SDK, if possible, make sure the problem persist in the latest SDK version.

Describe the bug I’ve been trying to access the .Properties field on the RequestMessage in my custom type deriving from RequestHandler after setting the ItemRequestOptions.Properties and passing it into Container.ReadItemAsync() but every time I would inspect the RequestMessage.Properties field while debugging, it was empty.

I read through the source code for ReadItemAsync and noticed we perform a different operation if BulkOperationIsSupported. When stepping into the method called in this conditional, I saw that we cast RequestOptions to ItemRequestOptions here. When I attempt this cast in my own code, the result of the cast is always null. I suspect this could be the source of the issue.

When I removed the AllowBulkExecution=true bool from my CosmosClientOptions setup, the RequestMessage.Properties in my custom RequestHandler had the properties correctly set from what I passed in from ItemRequestOptions.

To Reproduce

  1. Set up CosmosClient and pass in CosmosClientOptions with AllowBulkExcution set to true.
  2. Add a custom request handler which derives from RequestHandler
  3. Add a Container.ReadItemAsync() method and pass in an object of type ItemRequestOptions with any properties populated.
  4. Put a breakpoint in the custom request handler .SendAsync() method.
  5. Run the program so that it calls the ReadItemAsync() method.
  6. When the breakpoint is hit in .SendAsync(), inspect RequestMessage.Properties.

Expected behavior I expected the fields from the ItemRequestOptions passed into Container.ReadItemAsync() to be available on the RequestMessage in my custom RequestHandler.

Actual behavior None of my ItemRequestOptions fields were being populated on the RequestMessage when inside my custom RequestHandler.SendAsync() method.

Environment summary SDK Version: 3.21.0 OS Version: Windows

Additional context image

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ealsurcommented, Sep 20, 2021

This is by design on Bulk. When Bulk mode is on, the operation does not equal the actual network request. The network request is a grouping of operations, which Properties would be sent then? An aggregation of all the Properties of all the grouped operations? What if they have Properties with the same key?

0reactions
radmintcommented, Sep 20, 2021

Sounds good, thanks for the info, feel free to close!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ItemRequestOptions Class (Microsoft.Azure.Cosmos)
Application opted Cosmos request context that flow through with the RequestMessage. Context will be available through handlers.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found