Skip to content

Updating Elements Code value does not clear InstanceKeyCache #8631

@DanRod1999

Description

@DanRod1999

Describe the bug
Element's instanceKeyCache is not properly cleared when updating an element's code value. This bug was found in an imodel-transformer test and can be replicated with this test below added to IModel.test.ts. Note a better/simpler test should be written since this was specific to transforming elements. Just updating one element's code should suffice.

To Reproduce

  it.only("should successfully process changes when Definition Elements' codeValues are switched around", async () => {
    const dbFileName = IModelTestUtils.prepareOutputFile("IModel", "change-codeValues.bim");
    const imodelDb = SnapshotDb.createEmpty(dbFileName, {
      rootSubject: { name: "change-codeValues" },
    });
    let categoryA = SpatialCategory.create(
      imodelDb,
      IModel.dictionaryId,
      "A"
    );
    let categoryB = SpatialCategory.create(
      imodelDb,
      IModel.dictionaryId,
      "B"
    );
    categoryA.userLabel = "A";
    categoryB.userLabel = "B";
    categoryA.insert();
    categoryB.insert();
    imodelDb.saveChanges();

    categoryA = imodelDb.elements.getElement(
      SpatialCategory.createCode(imodelDb, IModel.dictionaryId, "A")
    );
    categoryB = imodelDb.elements.getElement(
      SpatialCategory.createCode(imodelDb, IModel.dictionaryId, "B")
    );
    categoryA.code.value = "temp";
    categoryA.update();
    categoryB.code.value = "A";
    categoryB.update();
    categoryA.code.value = "B";
    categoryA.update();
    imodelDb.saveChanges();

    categoryA = imodelDb.elements.getElement(
      SpatialCategory.createCode(imodelDb, IModel.dictionaryId, "A")
    );
    categoryB = imodelDb.elements.getElement(
      SpatialCategory.createCode(imodelDb, IModel.dictionaryId, "B")
    );

Expected behavior
userLabel of category should properly update, and element cached results should be cleared during update
-->

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions