Skip to content

Commit 62a1378

Browse files
rekhoffjdetter
andauthored
Moved Remove operation to start of Table.Apply (#2967)
Co-authored-by: John Detter <4099508+jdetter@users.noreply.github.com>
1 parent 7fb4df4 commit 62a1378

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

sdks/csharp/src/Table.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,15 @@ void IRemoteTableHandle.Apply(IEventContext context, MultiDictionaryDelta<object
303303
// This is a local operation -- it only looks at our indices and doesn't invoke user code.
304304
// So we don't need to wait for other tables to be updated to do it.
305305
// (And we need to do it before any PostApply is called.)
306+
// Reminder: We need to loop through the removed entries to delete them prior to inserting the new entries,
307+
// in order to avoid keys an error with the same key already added.
308+
foreach (var (_, value) in wasRemoved)
309+
{
310+
if (value is Row oldRow)
311+
{
312+
OnInternalDeleteHandler.Invoke(oldRow);
313+
}
314+
}
306315
foreach (var (_, value) in wasInserted)
307316
{
308317
if (value is Row newRow)
@@ -335,14 +344,6 @@ void IRemoteTableHandle.Apply(IEventContext context, MultiDictionaryDelta<object
335344
throw new Exception($"Invalid row type for table {RemoteTableName}: {newValue.GetType().Name}");
336345
}
337346
}
338-
339-
foreach (var (_, value) in wasRemoved)
340-
{
341-
if (value is Row oldRow)
342-
{
343-
OnInternalDeleteHandler.Invoke(oldRow);
344-
}
345-
}
346347
}
347348

348349
void IRemoteTableHandle.PostApply(IEventContext context)

0 commit comments

Comments
 (0)