Azure / Azure/data-api-builder

[Bug]: multiple configuration rest error

Open
#3,102 5 comments 0 reactions 1 assignee Assigned to @Aniruddh25 View on GitHub
bug cri triage
Dominant language
C#
Stars
1.5k
Forks
370
Avg merge
3d 17h
Merged PRs (30d)
8

Description

### What happened?

Experienced an error with the multiple configuration setup

**-- database setup**
create database databasea
go

create database databaseb
go
use databaseb
go
create table tableb
(
columnb1 int,
columnb2 int,
columnb3 varchar(10)
)
go
insert into tableb select 1,2,'s'
go

**--top-level configuration file: dab-config.json**

{
"$schema": "https://github.com/Azure/data-api-builder/releases/download/v1.6.84/dab.draft.schema.json",
"data-source": {
"database-type": "mssql",
"connection-string": "Server=localhost;Database=databasea;Integrated Security=true;Encrypt=True;TrustServerCertificate=True;",
"options": {
"set-session-context": false
}
},
"data-source-files": [
"dab-config-databaseb.json"
],
"runtime": {
"rest": {
"enabled": true,
"path": "/xapi",
"request-body-strict": true
},
"host": {
"mode": "development"
}
},
"entities": {
}
}
**--child level configuration file: dab-config-databaseb.json**
{
"$schema": "https://github.com/Azure/data-api-builder/releases/download/v1.6.84/dab.draft.schema.json",
"data-source": {
"database-type": "mssql",
"connection-string": "Server=localhost;Database=databaseb;Integrated Security=true;Encrypt=True;TrustServerCertificate=True;",
"options": {
"set-session-context": false
}
},
"entities": {
"tableb": {
"source": {
"object": "dbo.tableb",
"type": "table",
"key-fields": [
"columnb1",
"columnb2"
]
},
"rest": {
"enabled": true
},
"permissions": [
{
"role": "anonymous",
"actions": [
{
"action": "*"
}
]
}
]
}
}
}
**--Recreate the error**

curl -X "PATCH" "http://localhost:8080/xapi/tableb/columnb1/1/columnb2/23" -H "accept: application/json" -H "Content-Type: application/json" -d "{""columnb3"":""x""}"

### Version

Microsoft.DataApiBuilder 1.6.84

### What database are you using?

Azure SQL

### What hosting model are you using?

Local (including CLI)

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

REST

### Relevant log output

```Text
Information: Microsoft.DataApiBuilder 1.6.84
Information: Config not provided. Trying to get default config based on DAB_ENVIRONMENT...
Information: Environment variable DAB_ENVIRONMENT is (null)
Loading config file from C:\Users\username\dev\code\angular\dab\dab-config.json.
Loading config file from C:\Users\username\dev\code\angular\dab\dab-config-databaseb.json.
Monitoring config: dab-config.json for hot-reloading.
Information: Loaded config file: dab-config.json
Information: Setting default minimum LogLevel: Debug for Development mode.
Starting the runtime engine...
Loading config file from C:\Users\username\dev\code\angular\dab\dab-config.json.
Loading config file from C:\Users\username\dev\code\angular\dab\dab-config-databaseb.json.
Monitoring config: dab-config.json for hot-reloading.
Monitoring config: dab-config.json for hot-reloading.
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[63]
User profile is available. Using 'C:\Users\username\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
info: Azure.DataApiBuilder.Core.Services.ISqlMetadataProvider[0]
[tableb] REST path: /xapi/tableb
dbug: Azure.DataApiBuilder.Core.Resolvers.IQueryExecutor[0]
Executing query: SELECT STE.type_desc FROM sys.triggers ST inner join sys.trigger_events STE On ST.object_id = STE.object_id AND ST.parent_id = object_id(@param0 + '.' + @param1) WHERE ST.is_disabled = 0;
dbug: Azure.DataApiBuilder.Core.Resolvers.IQueryExecutor[0]
Executing query: SELECT ifsc.COLUMN_NAME from sys.columns as sc INNER JOIN INFORMATION_SCHEMA.COLUMNS as ifsc ON (sc.is_computed = 1 or ifsc.DATA_TYPE = 'timestamp') AND sc.object_id = object_id(@param0+'.'+@param1) AND ifsc.TABLE_SCHEMA = @param0 AND ifsc.TABLE_NAME = @param1 AND ifsc.COLUMN_NAME = sc.name;
dbug: Azure.DataApiBuilder.Core.Services.ISqlMetadataProvider[0]
Logging primary key information for entity: tableb.
dbug: Azure.DataApiBuilder.Core.Services.ISqlMetadataProvider[0]
Primary key column name: columnb1
Primary key mapped name: columnb1
Type: Int32
IsNullable: True
IsAutoGenerated: False
dbug: Azure.DataApiBuilder.Core.Services.ISqlMetadataProvider[0]
Primary key column name: columnb2
Primary key mapped name: columnb2
Type: Int32
IsNullable: True
IsAutoGenerated: False
info: Azure.DataApiBuilder.Service.Startup[0]
Successfully completed runtime initialization.
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:8080
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\Users\username\dev\code\angular\dab
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 PATCH http://localhost:8080/xapi/tableb/columnb1/1/columnb2/23 - application/json 16
warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
Failed to determine the https port for redirect.
dbug: Azure.DataApiBuilder.Core.AuthenticationHelpers.ClientRoleHeaderAuthenticationMiddleware[0]
f08344df-d1a8-4a80-8364-55d52d3f7bd7 AuthN state: Anonymous. Role: Anonymous. Scheme: StaticWebAppsAuthentication
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint 'Azure.DataApiBuilder.Service.Controllers.RestController.UpsertIncremental (Azure.DataApiBuilder.Service)'
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[102]
Route matched with {action = "UpsertIncremental", controller = "Rest"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.IActionResult] UpsertIncremental(System.String) on controller Azure.DataApiBuilder.Service.Controllers.RestController (Azure.DataApiBuilder.Service).
fail: Azure.DataApiBuilder.Service.Controllers.RestController[0]
f08344df-d1a8-4a80-8364-55d52d3f7bd7 Internal server error occured during REST request processing.
System.Collections.Generic.KeyNotFoundException: The given key 'tableb' was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at Azure.DataApiBuilder.Core.Resolvers.BaseQueryStructure..ctor(ISqlMetadataProvider metadataProvider, IAuthorizationResolver authorizationResolver, GQLFilterParser gQLFilterParser, List`1 predicates, String entityName, IncrementingInteger counter) in /_/src/Core/Resolvers/BaseQueryStructure.cs:line 105
at Azure.DataApiBuilder.Core.Resolvers.BaseSqlQueryStructure..ctor(ISqlMetadataProvider metadataProvider, IAuthorizationResolver authorizationResolver, GQLFilterParser gQLFilterParser, List`1 predicates, String entityName, IncrementingInteger counter, HttpContext httpContext, EntityActionOperation operationType, Boolean isLinkingEntity) in /_/src/Core/Resolvers/Sql Query Structures/BaseSqlQueryStructure.cs:line 64
at Azure.DataApiBuilder.Core.Resolvers.SqlUpsertQueryStructure..ctor(String entityName, ISqlMetadataProvider sqlMetadataProvider, IAuthorizationResolver authorizationResolver, GQLFilterParser gQLFilterParser, IDictionary`2 mutationParams, Boolean incrementalUpdate, HttpContext httpContext) in /_/src/Core/Resolvers/Sql Query Structures/SqlUpsertQueryStructure.cs:line 68
at Azure.DataApiBuilder.Core.Resolvers.SqlMutationEngine.PerformUpsertOperation(IDictionary`2 parameters, RestRequestContext context, ISqlMetadataProvider sqlMetadataProvider) in /_/src/Core/Resolvers/SqlMutationEngine.cs:line 1961
at Azure.DataApiBuilder.Core.Resolvers.SqlMutationEngine.ExecuteAsync(RestRequestContext context) in /_/src/Core/Resolvers/SqlMutationEngine.cs:line 556
at Azure.DataApiBuilder.Core.Services.RestService.ExecuteAsync(String entityName, EntityActionOperation operationType, String primaryKeyRoute) in /_/src/Core/Services/RestService.cs:line 202
at Azure.DataApiBuilder.Service.Controllers.RestController.HandleOperation(String route, EntityActionOperation operationType) in /_/src/Service/Controllers/RestController.cs:line 239
info: Microsoft.AspNetCore.Mvc.Infrastructure.SystemTextJsonResultExecutor[1]
Executing JsonResult, writing value of type '<>f__AnonymousType0`1[[<>f__AnonymousType1`3[[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.Int32, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], Azure.DataApiBuilder.Service, Version=1.6.84.0, Culture=neutral, PublicKeyToken=null]]'.
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[105]
Executed action Azure.DataApiBuilder.Service.Controllers.RestController.UpsertIncremental (Azure.DataApiBuilder.Service) in 105.6303ms
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
Executed endpoint 'Azure.DataApiBuilder.Service.Controllers.RestController.UpsertIncremental (Azure.DataApiBuilder.Service)'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished HTTP/1.1 PATCH http://localhost:8080/xapi/tableb/columnb1/1/columnb2/23 - 500 - application/json;+charset=utf-8 166.5703ms
```

### Code of Conduct

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.