From f4858b0892f7f18926163222e1af3cfa5dbbe024 Mon Sep 17 00:00:00 2001 From: Dion Date: Fri, 26 Apr 2024 15:29:08 +0200 Subject: [PATCH 1/2] #1564 concurrency conflicts bug --- .../Query/SolveConcurrency.cs | 16 ++++++++++++---- .../QueryTest/QueryUpdateItem_Error.cs | 12 ++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/starsky/starsky.foundation.database/Query/SolveConcurrency.cs b/starsky/starsky.foundation.database/Query/SolveConcurrency.cs index 28e8caa175..8b870c11e0 100644 --- a/starsky/starsky.foundation.database/Query/SolveConcurrency.cs +++ b/starsky/starsky.foundation.database/Query/SolveConcurrency.cs @@ -7,6 +7,10 @@ namespace starsky.foundation.database.Query { public static class SolveConcurrency { + /// + /// Make sure you add the right type in the check + /// + /// Entry items internal static void SolveConcurrencyExceptionLoop( IReadOnlyList concurrencyExceptionEntries) { @@ -29,20 +33,24 @@ internal static void SolveConcurrencyExceptionLoop( /// Database concurrency refers to situations in which multiple processes or users access or change the same data in a database at the same time. /// @see: https://docs.microsoft.com/en-us/ef/core/saving/concurrency /// - /// item + /// item /// new update /// old database item /// meta name /// entry item /// unknown how to fix - internal static void SolveConcurrencyException(object entryEntity, + internal static void SolveConcurrencyException(object _, PropertyValues proposedValues, PropertyValues? databaseValues, string entryMetadataName, OriginalValuesSetValuesDelegate entryOriginalValuesSetValues) { - if ( !( entryEntity is FileIndexItem ) ) + if ( _ is not FileIndexItem && + _ is not ThumbnailItem && + _ is not NotificationItem) + { throw new NotSupportedException( - "Don't know how to handle concurrency conflicts for " + "[SolveConcurrency] Don't know how to handle concurrency conflicts for " + entryMetadataName); + } foreach ( var property in proposedValues.Properties ) { diff --git a/starsky/starskytest/starsky.foundation.database/QueryTest/QueryUpdateItem_Error.cs b/starsky/starskytest/starsky.foundation.database/QueryTest/QueryUpdateItem_Error.cs index a096a99731..5ea3fa5ac0 100644 --- a/starsky/starskytest/starsky.foundation.database/QueryTest/QueryUpdateItem_Error.cs +++ b/starsky/starskytest/starsky.foundation.database/QueryTest/QueryUpdateItem_Error.cs @@ -506,9 +506,7 @@ public override object? this[IProperty property] public void SolveConcurrencyException_should_callDelegate() { SolveConcurrency.SolveConcurrencyException(new FileIndexItem(), -#pragma warning disable 8625 - new FakePropertyValues(null), new FakePropertyValues(null), -#pragma warning restore 8625 + new FakePropertyValues(null!), new FakePropertyValues(null!), "", _ => IsWrittenConcurrencyException = true); Assert.IsTrue(IsCalledDbUpdateConcurrency); @@ -519,14 +517,11 @@ public void SolveConcurrencyException_should_callDelegate() public void Query_UpdateItem_NotSupportedException() { SolveConcurrency.SolveConcurrencyException(null!, -#pragma warning disable 8625 - new FakePropertyValues(null), new FakePropertyValues(null), -#pragma warning restore 8625 + new FakePropertyValues(null!), new FakePropertyValues(null!), "", _ => IsWrittenConcurrencyException = true); // expect error } - private class AppDbInvalidOperationException : ApplicationDbContext { public AppDbInvalidOperationException(DbContextOptions options) : base(options) @@ -722,7 +717,8 @@ public async Task Query_AddRangeAsync_DoubleConcurrencyException() }; await fakeQuery.AddRangeAsync(fileIndexItemList); - + await fakeQuery.AddRangeAsync(fileIndexItemList); + Assert.IsTrue(IsCalledDbUpdateConcurrency); } From c723cec1a9e2569987dbed41a2ab6b043318837f Mon Sep 17 00:00:00 2001 From: Dion Date: Fri, 26 Apr 2024 15:31:01 +0200 Subject: [PATCH 2/2] keep a changelog --- history.md | 1 + 1 file changed, 1 insertion(+) diff --git a/history.md b/history.md index 9b3fe042f4..09c06a728e 100644 --- a/history.md +++ b/history.md @@ -49,6 +49,7 @@ Semantic Versioning 2.0.0 is from version 0.1.6+ - [x] (Changed) Back-end Upgrade to .NET 8 - SDK 8.0.204 (Runtime: 8.0.4) (PR #1541) - [x] (Fixed) _Back-end_ Unhandled exception DbUpdateException (PR #1558 Issue #1489) - [x] (Fixed) _Back-end_ Regex timeout IsExtensionForce (PR #1542 Issue #1537) +- [x] (Fixed) _Back-end_ Concurrency conflicts bug (PR #1565 Issue #1564) ## version 0.6.0 - 2024-03-15 {#v0.6.0}