Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Constraint error on migration of commands from Storage Account table to PgSql #1985

Closed
Metal-Mighty opened this issue Apr 4, 2023 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@Metal-Mighty
Copy link
Contributor

Expected Behavior

We are migrating from v2.8.0 to the current latest release v4.8.0, the data from the Storage Account's tables should be migrated to the database.

Current Behavior

During the PgSql initialization, there is an error during the migration of commands

Steps to Reproduce

  1. Instantiate a Portal in version 2.8.0
  2. Add models and commands
  3. Update the image to 4.8.0
  4. Observe the world as it collapses

Context (Environment)

Portal version: 4.8.0 (migrating from 2.8.0)
LoRaWAN Stack version: N/A

Logs

2023-04-04T07:38:43.894114500Z PostgreSQL init process complete; ready for start up.
2023-04-04T07:38:43.894119700Z 
2023-04-04T07:38:43.974430644Z 2023-04-04 07:38:43.974 UTC [1] LOG:  starting PostgreSQL 14.7 on x86_64-pc-linux-musl, compiled by gcc (Alpine 12.2.1_git20220924-r4) 12.2.1 20220924, 64-bit
2023-04-04T07:38:43.983914537Z 2023-04-04 07:38:43.983 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2023-04-04T07:38:43.984611336Z 2023-04-04 07:38:43.984 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2023-04-04T07:38:44.004338822Z 2023-04-04 07:38:44.004 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-04-04T07:38:44.040334997Z 2023-04-04 07:38:44.035 UTC [50] LOG:  database system was shut down at 2023-04-04 07:38:43 UTC
2023-04-04T07:38:44.059554684Z 2023-04-04 07:38:44.054 UTC [1] LOG:  database system is ready to accept connections

2023-04-04T07:38:58.940309987Z 2023-04-04 07:38:58.940 UTC [59] ERROR:  null value in column "Name" of relation "DeviceModelCommands" violates not-null constraint
2023-04-04T07:38:58.940378687Z 2023-04-04 07:38:58.940 UTC [59] DETAIL:  Failing row contains (CommandId, 01234567890ABCDEF, t, 7, f, deviceModelId, null).
2023-04-04T07:38:58.940386587Z 2023-04-04 07:38:58.940 UTC [59] STATEMENT:  INSERT INTO "DeviceModelCommands" ("Id", "Confirmed", "DeviceModelId", "Frame", "IsBuiltin", "Name", "Port")
2023-04-04T07:38:58.940391387Z 	VALUES ($1, $2, $3, $4, $5, $6, $7)
2023-04-04T07:39:46.190143866Z Unhandled exception. EntityFramework.Exceptions.Common.CannotInsertNullException: Cannot insert null
2023-04-04T07:39:46.190182166Z  ---> Npgsql.PostgresException (0x80004005): 23502: null value in column "Name" of relation "DeviceModelCommands" violates not-null constraint
2023-04-04T07:39:46.190188166Z 
2023-04-04T07:39:46.190191566Z DETAIL: Detail redacted as it may contain sensitive data. Specify 'Include Error Detail' in the connection string to include this information.
2023-04-04T07:39:46.190195266Z    at Npgsql.Internal.NpgsqlConnector.<ReadMessage>g__ReadMessageLong|233_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
2023-04-04T07:39:46.190199266Z    at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
2023-04-04T07:39:46.190202966Z    at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
2023-04-04T07:39:46.190206266Z    at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
2023-04-04T07:39:46.190209666Z    at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
2023-04-04T07:39:46.190212966Z    at Npgsql.NpgsqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
2023-04-04T07:39:46.190216266Z    at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
2023-04-04T07:39:46.190219666Z    at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
2023-04-04T07:39:46.190223066Z    at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken)
2023-04-04T07:39:46.190226466Z   Exception data:
2023-04-04T07:39:46.190229666Z     Severity: ERROR
2023-04-04T07:39:46.190232766Z     SqlState: 23502
2023-04-04T07:39:46.190235966Z     MessageText: null value in column "Name" of relation "DeviceModelCommands" violates not-null constraint
2023-04-04T07:39:46.190239466Z     Detail: Detail redacted as it may contain sensitive data. Specify 'Include Error Detail' in the connection string to include this information.
2023-04-04T07:39:46.190242866Z     SchemaName: public
2023-04-04T07:39:46.190246066Z     TableName: DeviceModelCommands
2023-04-04T07:39:46.190265466Z     ColumnName: Name
2023-04-04T07:39:46.190269166Z     File: execMain.c
2023-04-04T07:39:46.190272366Z     Line: 1883
2023-04-04T07:39:46.190275466Z     Routine: ExecConstraints
2023-04-04T07:39:46.190278766Z    --- End of inner exception stack trace ---
2023-04-04T07:39:46.190281866Z    at EntityFramework.Exceptions.Common.ExceptionProcessorInterceptor`1.SaveChangesFailedAsync(DbContextErrorEventData eventData, CancellationToken cancellationToken)
2023-04-04T07:39:46.190285366Z    at Microsoft.EntityFrameworkCore.Diagnostics.CoreLoggerExtensions.SaveChangesFailedAsync(IDiagnosticsLogger`1 diagnostics, DbContext context, Exception exception, CancellationToken cancellationToken)
2023-04-04T07:39:46.190288666Z    at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess, CancellationToken cancellationToken)
2023-04-04T07:39:46.190292066Z    at AzureIoTHub.Portal.Server.Startup.EnsureDatabaseCreatedAndUpToDate(IApplicationBuilder app) in /src/AzureIoTHub.Portal.Server/Startup.cs:line 483
2023-04-04T07:39:46.190295366Z    at AzureIoTHub.Portal.Server.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in /src/AzureIoTHub.Portal.Server/Startup.cs:line 433
2023-04-04T07:39:46.190298766Z    at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
2023-04-04T07:39:46.190303166Z    at System.Threading.ThreadPoolWorkQueue.Dispatch()
2023-04-04T07:39:46.191958362Z    at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()

Additional Information

@Metal-Mighty Metal-Mighty added the bug Something isn't working label Apr 4, 2023
@github-project-automation github-project-automation bot moved this to 📝 Todo in IoT Hub Portal Apr 4, 2023
@kbeaugrand kbeaugrand self-assigned this Apr 4, 2023
@kbeaugrand
Copy link
Member

@Metal-Mighty can you try v4.8.1, should fix that.

@kbeaugrand kbeaugrand moved this from 📝 Todo to 🚀 Ready in IoT Hub Portal Apr 4, 2023
@Metal-Mighty
Copy link
Contributor Author

Fixed in v4.8.1, thanks ! (I have another exception but I'll open another issue 😉)

@kbeaugrand kbeaugrand linked a pull request Jun 19, 2023 that will close this issue
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 🚀 Ready
Development

Successfully merging a pull request may close this issue.

2 participants