Azure / Azure/data-api-builder

[Bug]: Multiple REST API requests fail when "set-session-context": true

Open
#2,178 1 comment 0 reactions 0 assignees View on GitHub
bug triage
Dominant language
C#
Stars
1.5k
Forks
370
Avg merge
3d 22h
Merged PRs (30d)
9

Description

### What happened?

When requesting for multiple api requests when session context is "set-session-context": true.
This is for using DB Type: DWSQL for using against Fabric SQL endpoints.

It causes the following api response:

{
"error": {
"code": "DatabaseOperationFailed",
"message": "Cannot set key 'aud' in the session context. The key has been set as read_only for this session.",
"status": 500
}
}

I am assuming the session is being sticky and not starting new sessions for each call.
For some reason it may be caching the session when "set-session-context": true, but from my understanding that should default to false.

### Version

0.11.130

### What database are you using?

Azure SQL

### What hosting model are you using?

Container Apps

### Which API approach are you accessing DAB through?

REST

### Relevant log output

```Text
fail: Azure.DataApiBuilder.Service.Controllers.RestController[0]
7c081014-1d46-44a5-ac17-d5a9e7532d8c Error handling REST request.
Azure.DataApiBuilder.Service.Exceptions.DataApiBuilderException: Cannot set key 'aud' in the session context. The key has been set as read_only for this session.
---> Microsoft.Data.SqlClient.SqlException (0x80131904): Cannot set key 'aud' in the session context. The key has been set as read_only for this session.
at Microsoft.Data.SqlClient.SqlCommand.<>c.b__211_0(Task`1 result)
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
at Azure.DataApiBuilder.Core.Resolvers.QueryExecutor`1.ExecuteQueryAgainstDbAsync[TResult](TConnection conn, String sqltext, IDictionary`2 parameters, Func`3 dataReaderHandler, HttpContext httpContext, String dataSourceName, List`1 args)
ClientConnectionId:72047e37-8ca4-4d5c-9947-ebd8551d6518
Error Number:15664,State:1,Class:16
ClientConnectionId before routing:7783f539-dec7-4b05-810f-4a560d0de35b
Routing Destination:*****
--- End of inner exception stack trace ---
```

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Research direction

Start by tracing the REST request through Azure.DataApiBuilder.Service.Controllers.RestController and Azure.DataApiBuilder.Core.Resolvers.QueryExecutor.ExecuteQueryAgainstDbAsync, using the supplied session-context configuration and error log. Reproduce multiple requests against Azure SQL and determine why the 'aud' key is set read-only more than once; done means repeated requests no longer return this 500 error.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp, sql
Domain
api, backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.