From 0ca9b767edafe5eb6d92452e5a14d0de4dc89fa7 Mon Sep 17 00:00:00 2001 From: Alexandre Brandizzi Date: Wed, 23 Sep 2026 01:39:16 -0300 Subject: [PATCH] fix: distinguish uplift request key conflicts --- .../Implementation/UpliftDataService.cs | 10 +++++++--- SeaHaven.DataServices/Properties/AssemblyInfo.cs | 1 + .../UpliftDataServiceTransactionTests.cs | 10 ++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/SeaHaven.DataServices/Implementation/UpliftDataService.cs b/SeaHaven.DataServices/Implementation/UpliftDataService.cs index a41d487..64df777 100644 --- a/SeaHaven.DataServices/Implementation/UpliftDataService.cs +++ b/SeaHaven.DataServices/Implementation/UpliftDataService.cs @@ -547,9 +547,7 @@ namespace SeaHaven.DataServices.Implementation { var number = exceptionType.GetProperty("Number")?.GetValue(databaseException) as int?; return number is 2601 or 2627 - && databaseException.Message.Contains( - "IX_DispatchUpliftRequests_DispatchId", - StringComparison.OrdinalIgnoreCase); + && IsActiveDispatchIndexViolationMessage(databaseException.Message); } if (provider?.Contains("Sqlite", StringComparison.OrdinalIgnoreCase) == true @@ -576,6 +574,12 @@ namespace SeaHaven.DataServices.Implementation return false; } + internal static bool IsActiveDispatchIndexViolationMessage(string message) + { + const string activeDispatchIndex = "'IX_DispatchUpliftRequests_DispatchId'"; + return message.Contains(activeDispatchIndex, StringComparison.OrdinalIgnoreCase); + } + public async Task ExecuteWorkOrderMutationAsync( int workOrderId, Func> work, diff --git a/SeaHaven.DataServices/Properties/AssemblyInfo.cs b/SeaHaven.DataServices/Properties/AssemblyInfo.cs index 75fc406..15ea248 100644 --- a/SeaHaven.DataServices/Properties/AssemblyInfo.cs +++ b/SeaHaven.DataServices/Properties/AssemblyInfo.cs @@ -1,3 +1,4 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Api.SeaHavenIndustries.Tests")] +[assembly: InternalsVisibleTo("SeaHavenIndustries.Tests")] diff --git a/SeaHavenIndustries.Tests/UpliftDataServiceTransactionTests.cs b/SeaHavenIndustries.Tests/UpliftDataServiceTransactionTests.cs index 1742f32..2825fcd 100644 --- a/SeaHavenIndustries.Tests/UpliftDataServiceTransactionTests.cs +++ b/SeaHavenIndustries.Tests/UpliftDataServiceTransactionTests.cs @@ -9,6 +9,16 @@ namespace SeaHavenIndustries.Tests; public sealed class UpliftDataServiceTransactionTests { + [Theory] + [InlineData("Cannot insert duplicate key row with unique index 'IX_DispatchUpliftRequests_DispatchId'.", true)] + [InlineData("Cannot insert duplicate key row with unique index 'IX_DispatchUpliftRequests_DispatchId_RequestKey'.", false)] + public void IsActiveDispatchIndexViolationMessage_MatchesOnlyTheActiveDispatchIndex( + string message, + bool expected) + { + Assert.Equal(expected, UpliftDataService.IsActiveDispatchIndexViolationMessage(message)); + } + [Fact] public async Task SaveChangesAsync_ActiveUpliftOnSameDispatch_MapsConcurrentInsertConflict() {