Azure / Azure/data-api-builder

[Bug]: Cannot obtain Schema for entity

Aperta
#2,227 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub
🛠️troubleshooting cri
Lingua principale
C#
Stelle
1.5k
Fork
370
Merge medio
3g 22h
PR unite (30g)
9

Descrizione

I'm trying to start dab with this configuration
```{
"$schema": "https://github.com/Azure/data-api-builder/releases/download/v1.1.7/dab.draft.schema.json",
"data-source": {
"database-type": "mssql",
"connection-string": "@env('cnn')",
"options": {
"set-session-context": false
}
},
"runtime": {
"rest": {
"enabled": true,
"path": "/api",
"request-body-strict": true
},
"graphql": {
"enabled": true,
"path": "/graphql",
"allow-introspection": true,
"multiple-mutations": {
"create": {
"enabled": true
}
}
},
"host": {
"cors": {
"origins": [],
"allow-credentials": false
},
"authentication": {
"provider": "StaticWebApps"
},
"mode": "development"
}
},
"entities": {
"MGAnaArt": {
"source": {
"object": "dbo.MG_AnaArt",
"type": "table"
},
"graphql": {
"enabled": true,
"type": {
"singular": "MGAnaArt",
"plural": "MGAnaArts"
}
},
"rest": {
"enabled": true
},
"permissions": [
{
"role": "anonymous",
"actions": [
{
"action": "*"
}
]
}
]
}
}
}
```

where the user used in the connection string is a SQL user.
Running the dab from one computer starts fine, however when running on another PC with the same user and password the error shown in the "Relevant log output" section appears

Using the sql profiler, we saw that there is no query to the database when run with `dab start`.
If instead the `dab validate` command is used, dab correctly accesses the database (activity is always displayed via profiler) and dab detects, for example, the triggers present on the table as per the output

```
Information: Microsoft.DataApiBuilder 1.1.7
Information: Config not provided. Trying to get default config based on DAB_ENVIRONMENT...
Information: Environment variable DAB_ENVIRONMENT is (null)
Information: Validating config file: dab-config.json
Loading config file from dab-config.json.
Information: The config satisfies the schema requirements.
Information: Validating entity relationships.
Information: [MGAnaArt] REST path: /api/MGAnaArt
Information: An insert trigger is enabled for the entity: MGAnaArt
Information: An update trigger is enabled for the entity: MGAnaArt
Information: An update trigger is enabled for the entity: MGAnaArt
Information: An insert trigger is enabled for the entity: MGAnaArt
Information: Config is valid.
```

### Version

1.1.7

### What database are you using?

Azure SQL

### What hosting model are you using?

_No response_

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

GraphQL

### Relevant log output

```Text
Information: Microsoft.DataApiBuilder 1.1.7
Information: Config not provided. Trying to get default config based on DAB_ENVIRONMENT...
Information: Environment variable DAB_ENVIRONMENT is (null)
Loading config file from dab-config.json.
Information: Loaded config file: dab-config.json
Information: Setting default minimum LogLevel: Debug for Development mode.
Starting the runtime engine...
Loading config file from dab-config.json.
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[63]
User profile is available. Using 'C:\Users\myuser\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
info: Azure.DataApiBuilder.Core.Services.ISqlMetadataProvider[0]
[MGAnaArt] REST path: /api/MGAnaArt
fail: Azure.DataApiBuilder.Service.Startup[0]
Unable to complete runtime initialization. Refer to exception for error details.
Azure.DataApiBuilder.Service.Exceptions.DataApiBuilderException: Cannot obtain Schema for entity MGAnaArt with underlying database object source: dbo.MG_AnaArt due to: Invalid object name 'dbo.MG_AnaArt'.
at Azure.DataApiBuilder.Core.Services.SqlMetadataProvider`3.HandleOrRecordException(Exception e) in /_/src/Core/Services/MetadataProviders/SqlMetadataProvider.cs:line 100
at Azure.DataApiBuilder.Core.Services.SqlMetadataProvider`3.PopulateObjectDefinitionForEntity(String entityName, Entity entity) in /_/src/Core/Services/MetadataProviders/SqlMetadataProvider.cs:line 1116
at Azure.DataApiBuilder.Core.Services.SqlMetadataProvider`3.PopulateObjectDefinitionForEntities() in /_/src/Core/Services/MetadataProviders/SqlMetadataProvider.cs:line 1054
at Azure.DataApiBuilder.Core.Services.SqlMetadataProvider`3.InitializeAsync() in /_/src/Core/Services/MetadataProviders/SqlMetadataProvider.cs:line 289
at Azure.DataApiBuilder.Core.Services.MetadataProviders.MetadataProviderFactory.InitializeAsync() in /_/src/Core/Services/MetadataProviders/MetadataProviderFactory.cs:line 65
at Azure.DataApiBuilder.Service.Startup.PerformOnConfigChangeAsync(IApplicationBuilder app) in /_/src/Service/Startup.cs:line 613
fail: Azure.DataApiBuilder.Service.Startup[0]
Could not initialize the engine with the runtime config file: dab-config.json
info: Microsoft.Hosting.Lifetime[0]
Application is shutting down...
fail: Microsoft.Extensions.Hosting.Internal.Host[11]
Hosting failed to start
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
at Microsoft.Extensions.Hosting.Internal.Host.b__15_1(IHostedService service, CancellationToken token)
at Microsoft.Extensions.Hosting.Internal.Host.ForeachService[T](IEnumerable`1 services, CancellationToken token, Boolean concurrent, Boolean abortOnFirstException, List`1 exceptions, Func`3 operation)
Unable to launch the Data API builder engine.
Error: Failed to start the engine.
```

### Code of Conduct

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

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Riprodurre con dab-config.json eseguendo dab validate e poi dab start, confrontando l’attività del database e i log di inizializzazione. Iniziare da src/Core/Services/MetadataProviders/SqlMetadataProvider.cs alle righe 100, 289, 1054 e 1116, quindi esaminare src/Service/Startup.cs alla riga 613. Il lavoro è completato quando dab start inizializza l’entità MGAnaArt senza l’errore di oggetto non valido, mentre la convalida continua ad avere esito positivo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
azure, csharp, graphql, sql
Ambito
api, backend, databases
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.