iTwin / imodel-transformer

API for exporting an iModel's parts and also importing them into another iModel
MIT License
3 stars 2 forks source link

Ignore model remaps for subjects and always present root elements, so we don't report unresolved references. #167

Closed nick4598 closed 1 month ago

nick4598 commented 2 months ago

Background Information:

Problem In scenarios where we remap the rootSubject to some other non-root subject like: transformerA2S.context.remapElement(IModel.rootSubjectId, subjectId);

This puts ourselves in a situation where the transformer will falsely report partially committed entities like the below. image

This is caused by the below code called in private collectUnmappedReferences inside IModelTransformer.ts. image

When searching for a referenceIdInTarget it attempts to find m0x1, but there is a remapping rule from 0x1 (rootSubjectId) to another subjectId. So it looks for m${subjectId} instead of m${rootSubjectId} which does not exist. image

Since all subjects have their model as the repositoryModel, there is never a model inserted which corresponds to m${subjectId} and so it cannot be found. This will also be a problem for other elements who have the model as their repositoryModel as you can see by the first screenshot which lists 0xe, 0x10, 0x1, 0x12, 0x19.

The test to use in this case is it("should log unresolved references", in IModelTransformer.test.ts. A conditional breakpoint where entity.id === "0x1" within collectUnmappedReferences is a good one to understand what is occurring.

Fix When doing findTargetElementId in 'findTargetEntityId' we should not use what we get as a return when our sourceid is m0x1 and instead just set it to the repositoryModel.