Skip to content

Commit 7bd2a81

Browse files
authored
Tolerate complex form parent already deleted during FwData sync (#2374)
1 parent 57883f9 commit 7bd2a81

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1088,12 +1088,15 @@ private ICmObject FindSenseOrEntryComponent(ComplexFormComponent component)
10881088

10891089
public Task DeleteComplexFormComponent(ComplexFormComponent complexFormComponent)
10901090
{
1091+
//complex form entry has been deleted, so this component relationship is gone already
1092+
if (!EntriesRepository.TryGetObject(complexFormComponent.ComplexFormEntryId, out var lexEntry))
1093+
return Task.CompletedTask;
1094+
10911095
UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW("Delete Complex Form Component",
10921096
"Add Complex Form Component",
10931097
Cache.ServiceLocator.ActionHandler,
10941098
() =>
10951099
{
1096-
var lexEntry = EntriesRepository.GetObject(complexFormComponent.ComplexFormEntryId);
10971100
RemoveComplexFormComponent(lexEntry, complexFormComponent);
10981101
});
10991102
return Task.CompletedTask;

backend/FwLite/FwLiteProjectSync.Tests/EntrySyncTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,27 @@ public async Task FwDataApiDoesNotUpdateMorphType()
168168
actual.Should().NotBeNull();
169169
actual.MorphType.Should().Be(MorphTypeKind.BoundStem);
170170
}
171+
172+
[Fact]
173+
public async Task SyncFull_RemovingComplexFormWhoseParentWasDeleted_DoesNotThrow()
174+
{
175+
var component = await Api.CreateEntry(new() { Id = Guid.NewGuid(), LexemeForm = { { "en", "component" } } });
176+
var complexForm = new Entry { Id = Guid.NewGuid(), LexemeForm = { { "en", "complexForm" } } };
177+
complexForm.Components = [ComplexFormComponent.FromEntries(complexForm, component)];
178+
await Api.CreateEntry(complexForm);
179+
180+
var before = await Api.GetEntry(component.Id);
181+
before!.ComplexForms.Should().ContainSingle();
182+
183+
// Deleting the parent already drops the relationship; the sync then redundantly removes it from the surviving component, which used to throw because the parent was gone.
184+
await Api.DeleteEntry(complexForm.Id);
185+
var after = before.Copy();
186+
after.ComplexForms.Clear();
187+
188+
await EntrySync.SyncFull(before, after, Api);
189+
190+
(await Api.GetEntry(component.Id)).Should().NotBeNull();
191+
}
171192
}
172193

173194
public abstract class EntrySyncTestsBase(ExtraWritingSystemsSyncFixture fixture) : IClassFixture<ExtraWritingSystemsSyncFixture>, IAsyncLifetime

0 commit comments

Comments
 (0)