Skip to content

Commit

Permalink
#4223 Restore app context if operation fails w/ no local clone
Browse files Browse the repository at this point in the history
  • Loading branch information
rockfordlhotka committed Nov 4, 2024
1 parent 5964aea commit 1fe0545
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Source/Csla/DataPortalT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

using System.Globalization;
using Csla.Configuration;
using Csla.Core;
using Csla.DataPortalClient;
using Csla.Properties;

Expand Down Expand Up @@ -470,9 +471,24 @@ internal async Task<T> DoUpdateAsync(T obj, bool isSync, CancellationToken ct =
// clone original object before saving
if (obj is ICloneable cloneable)
obj = (T)cloneable.Clone();
result = await Cache.GetDataPortalResultAsync(objectType, obj, operation,
async () => await proxy.Update(obj, dpContext, isSync));
}
else
{
var contextManager = _applicationContext.ApplicationContextAccessor;
try
{
result = await Cache.GetDataPortalResultAsync(objectType, obj, operation,
async () => await proxy.Update(obj, dpContext, isSync));
}
catch
{
if (obj is IUseApplicationContext useContext)
useContext.ApplicationContext.ApplicationContextAccessor = contextManager;
throw;
}
}
result = await Cache.GetDataPortalResultAsync(objectType, obj, operation,
async () => await proxy.Update(obj, dpContext, isSync));
}
catch (AggregateException ex)
{
Expand Down

0 comments on commit 1fe0545

Please sign in to comment.